{"record":{"id":"fd068f99c82a24fd","repo":"micro-editor/micro","slug":"error-finding-your-home-directory-can-t-load-confi","errorCode":null,"errorMessage":"Error finding your home directory\nCan't load config files: %s","messagePattern":"Error finding your home directory\nCan't load config files: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/config/config.go","lineNumber":26,"sourceCode":"\thomedir \"github.com/mitchellh/go-homedir\"\n)\n\nvar ConfigDir string\n\n// InitConfigDir finds the configuration directory for micro according to the XDG spec.\n// If no directory is found, it creates one.\nfunc InitConfigDir(flagConfigDir string) error {\n\tvar e error\n\n\tmicroHome := os.Getenv(\"MICRO_CONFIG_HOME\")\n\tif microHome == \"\" {\n\t\t// The user has not set $MICRO_CONFIG_HOME so we'll try $XDG_CONFIG_HOME\n\t\txdgHome := os.Getenv(\"XDG_CONFIG_HOME\")\n\t\tif xdgHome == \"\" {\n\t\t\t// The user has not set $XDG_CONFIG_HOME so we should act like it was set to ~/.config\n\t\t\thome, err := homedir.Dir()\n\t\t\tif err != nil {\n\t\t\t\treturn errors.New(\"Error finding your home directory\\nCan't load config files: \" + err.Error())\n\t\t\t}\n\t\t\txdgHome = filepath.Join(home, \".config\")\n\t\t}\n\n\t\tmicroHome = filepath.Join(xdgHome, \"micro\")\n\t}\n\tConfigDir = microHome\n\n\tif len(flagConfigDir) > 0 {\n\t\tif _, err := os.Stat(flagConfigDir); os.IsNotExist(err) {\n\t\t\te = errors.New(\"Error: \" + flagConfigDir + \" does not exist. Defaulting to \" + ConfigDir + \".\")\n\t\t} else {\n\t\t\tConfigDir = flagConfigDir\n\t\t\treturn nil\n\t\t}\n\t}\n\n\t// Create micro config home directory if it does not exist","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/micro-editor/micro/blob/1c8b82b32e408a5faf340039ed92d5266bea3293/internal/config/config.go#L8-L44","documentation":"Returned by config.InitConfigDir when neither MICRO_CONFIG_HOME nor XDG_CONFIG_HOME is set and the homedir library cannot determine the user's home directory (homedir.Dir() error). Without a home, micro cannot derive ~/.config/micro, so it reports it cannot load config files. The wrapped underlying error explains the specific failure.","triggerScenarios":"Running micro in an environment with a stripped env: no HOME on Unix (go-homedir falls back to `getent passwd`/shells; in minimal containers that can also fail), no USERPROFILE on Windows, or a container/cron/systemd unit that clears environment variables. Fires at internal/config/config.go:26.","commonSituations":"Docker containers run without HOME, CI jobs, `env -i micro`, cron entries, or launching micro from a service manager unit without a User= directive / environment block.","solutions":["Set HOME for the invoking user: export HOME=/home/$USER (or USERPROFILE on Windows).","Or set XDG_CONFIG_HOME to any absolute path: export XDG_CONFIG_HOME=/etc/xdg (micro then uses $XDG_CONFIG_HOME/micro).","Or set MICRO_CONFIG_HOME directly: export MICRO_CONFIG_HOME=/path/with/config — this bypasses home lookup entirely.","For containers: add `ENV HOME=/root` or a valid USER so passwd lookup works."],"exampleFix":"# before:\ndocker run --rm -it myimage micro   # no HOME set -> error\n\n# after:\ndocker run --rm -it -e HOME=/root myimage micro","handlingStrategy":"validation","validationCode":"func ensureConfigEnv() error {\n    if os.Getenv(\"MICRO_CONFIG_HOME\") != \"\" || os.Getenv(\"XDG_CONFIG_HOME\") != \"\" {\n        return nil\n    }\n    if os.Getenv(\"HOME\") == \"\" { // windows: USERPROFILE\n        return errors.New(\"no HOME set; micro cannot find its config dir\")\n    }\n    return nil\n}\n// run before invoking micro or config.InitConfigDir","typeGuard":null,"tryCatchPattern":"if err := config.InitConfigDir(\"\"); err != nil {\n    if strings.HasPrefix(err.Error(), \"Error finding your home directory\") {\n        // set a concrete config dir and retry: config.InitConfigDir(\"/tmp/micro-config\")\n    }\n}","preventionTips":["In containers/cron/systemd units, always set HOME (or USERPROFILE) or XDG_CONFIG_HOME for the run.","For deterministic embeds, pass -config-dir or MICRO_CONFIG_HOME explicitly so home lookup is skipped.","Fail fast in launch scripts: [ -n \"$HOME\" ] || export HOME=/tmp before exec micro."],"tags":["environment","config","home-directory","container","startup"],"backgroundTag":null,"analyzedSha":"1c8b82b32e408a5faf340039ed92d5266bea3293","analyzedAt":"2026-08-15T20:01:45.134Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}