{"record":{"id":"47864fd5529bed9a","repo":"wtfutil/wtf","slug":"cannot-expand-user-specific-home-dir","errorCode":null,"errorMessage":"cannot expand user-specific home dir","messagePattern":"cannot expand user-specific home dir","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cfg/config_files.go","lineNumber":176,"sourceCode":"\t\t\tos.Exit(1)\n\t\t}\n\t}\n}\n\n// Expand expands the path to include the home directory if the path\n// is prefixed with `~`. If it isn't prefixed with `~`, the path is\n// returned as-is.\nfunc expandHomeDir(path string) (string, error) {\n\tif path == \"\" {\n\t\treturn path, nil\n\t}\n\n\tif path[0] != '~' {\n\t\treturn path, nil\n\t}\n\n\tif len(path) > 1 && path[1] != '/' && path[1] != '\\\\' {\n\t\treturn \"\", errors.New(\"cannot expand user-specific home dir\")\n\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 == \"\" {","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/wtfutil/wtf/blob/bb838c1ccb0f0f3223690df44afdec663d622881/cfg/config_files.go#L158-L194","documentation":"expandHomeDir expands a leading '~' in a config path to the user's home directory. It only supports the forms '~' and '~/...' (or '~\\...'); any other character after the tilde (e.g. '~otheruser/docs') is unsupported and produces this error, because resolving another user's home is not attempted.","triggerScenarios":"Passing a config path like '~bob/wtf/config.yml' or '~root/...' to WtfConfigDir, LoadWtfConfigFile, chmodConfigFile, or migrateOldConfig; a WTF_CONFIG-style env var or -c flag containing '~username' syntax.","commonSituations":"Users copying Unix shell tilde-expansion conventions (which support ~user) into wtfutil config paths or launchd/systemd service definitions; typos like '~ name' or '~/~/x'.","solutions":["Use '~' or '~/...' form only; expand other users' homes yourself before calling","Pre-resolve the path with os.UserHomeDir() or os.ExpandEnv and pass an absolute path","Check for stray characters right after '~' in the path string (typo check)"],"exampleFix":"// before\nhome, err := cfg.LoadWtfConfigFile(\"~alice/.config/wtf/config.yml\")\n// after\naliceHome, _ := user.Lookup(\"alice\")\nhome, err := cfg.LoadWtfConfigFile(filepath.Join(aliceHome.HomeDir, \".config/wtf/config.yml\"))","handlingStrategy":"validation","validationCode":"if strings.HasPrefix(path, \"~\") && len(path) > 1 && path[1] != '/' && path[1] != '\\\\' {\n    return errors.New(\"only ~/ paths are supported, not ~user\")\n}","typeGuard":"func isExpandableTildePath(p string) bool {\n    return p == \"~\" || (len(p) > 1 && p[0] == '~' && (p[1] == '/' || p[1] == '\\\\'))\n}","tryCatchPattern":"path, err := cfg.ExpandHomeDir(rawPath)\nif err != nil {\n    log.Fatalf(\"bad config path %q: %v\", rawPath, err)\n}","preventionTips":["Never use ~user syntax in wtfutil config paths","Expand other users' homes with user.Lookup before passing paths","Prefer absolute paths in service/systemd configurations","Sanity-check paths copied from shell dotfile snippets"],"tags":["go","filesystem","path-expansion"],"backgroundTag":"home-dir-expansion-failed","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"}