{"record":{"id":"3be7fcedea873244","repo":"wtfutil/wtf","slug":"cannot-find-user-specific-home-dir","errorCode":null,"errorMessage":"cannot find user-specific home dir","messagePattern":"cannot find user-specific home dir","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cfg/config_files.go","lineNumber":195,"sourceCode":"\t}\n\n\tdir, err := home()\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn filepath.Join(dir, path[1:]), nil\n}\n\n// Dir returns the home directory for the executing user.\n// An error is returned if a home directory cannot be detected.\nfunc home() (string, error) {\n\tcurrentUser, err := user.Current()\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tif currentUser.HomeDir == \"\" {\n\t\treturn \"\", errors.New(\"cannot find user-specific home dir\")\n\t}\n\n\treturn currentUser.HomeDir, nil\n}\n\n// migrateOldConfig copies any existing configuration from the old location\n// to the new, XDG-compatible location\nfunc migrateOldConfig() {\n\tsrcDir, _ := expandHomeDir(WtfConfigDirV1)\n\tdestDir, _ := WtfConfigDir()\n\n\t// If the old config directory doesn't exist, do not move\n\tif _, err := os.Stat(srcDir); os.IsNotExist(err) {\n\t\treturn\n\t}\n\n\t// If the new config directory already exists, do not move\n\tif _, err := os.Stat(destDir); err == nil {","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/wtfutil/wtf/blob/bb838c1ccb0f0f3223690df44afdec663d622881/cfg/config_files.go#L177-L213","documentation":"home() resolves the current OS user's home directory via user.Current(). If the OS reports the user but with an empty HomeDir, this error is thrown because no path can be returned. It is the underlying failure of expandHomeDir for all '~'-prefixed config paths.","triggerScenarios":"Running in an environment where user.Current() succeeds but HomeDir is empty — e.g. misconfigured /etc/passwd entry, containers running as a UID with no passwd entry, CGO disabled with missing getent data, or stripped-down scratch/Distroless images.","commonSituations":"Docker containers running as non-root numeric UIDs without passwd entries; CI sandboxes with unset/mangled user records; cross-compiled static Go binaries (CGO_ENABLED=0) on minimal images where user lookup returns empty HomeDir.","solutions":["Ensure the runtime user has a valid passwd entry with a home directory (add the user or use useradd)","Set HOME and check `go env`/build flags: build with CGO_ENABLED=1 or use an image with proper nsswitch files","Avoid '~' paths: pass an absolute config path explicitly (WTF_CONFIG env var or -c flag)","Run as a normal user account instead of an arbitrary UID"],"exampleFix":"# before\nUSER 10001  # no passwd entry, HomeDir empty\n# after\nRUN useradd -m appuser\nUSER appuser","handlingStrategy":"fallback","validationCode":"u, err := user.Current()\nif err != nil || u.HomeDir == \"\" {\n    // don't rely on ~ expansion; set WTF_CONFIG or pass absolute path\n}","typeGuard":"func homeDirAvailable() bool {\n    u, err := user.Current()\n    return err == nil && u.HomeDir != \"\"\n}","tryCatchPattern":"if _, err := cfg.LoadWtfConfigFile(\"~/.config/wtf/config.yml\"); err != nil {\n    if strings.Contains(err.Error(), \"cannot find user-specific home\") {\n        cfgPath = os.Getenv(\"WTF_CONFIG\") // fallback\n    }\n}","preventionTips":["In containers, create the runtime user with a home directory (useradd -m)","Avoid CGO_ENABLED=0 static builds if OS user lookup matters, or set HOME explicitly","Set WTF_CONFIG to an absolute path in minimal environments","Smoke-test user.Current().HomeDir in your image before launch"],"tags":["go","filesystem","container","environment"],"backgroundTag":"home-directory-not-found","analyzedSha":"bb838c1ccb0f0f3223690df44afdec663d622881","analyzedAt":"2026-09-03T17:02:45.030Z","contentChangedAt":"2026-09-03T17:02:45.030Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}