{"record":{"id":"2e02a806e83afc52","repo":"wtfutil/wtf","slug":"cannot-expand-user-specific-home-dir-2e02a8","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":"utils/homedir.go","lineNumber":26,"sourceCode":"\t\"errors\"\n\t\"os\"\n\t\"path/filepath\"\n)\n\n// ExpandHomeDir 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 := os.UserHomeDir()\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn filepath.Join(dir, path[1:]), nil\n}\n","sourceCodeStart":8,"sourceCodeEnd":36,"githubUrl":"https://github.com/wtfutil/wtf/blob/bb838c1ccb0f0f3223690df44afdec663d622881/utils/homedir.go#L8-L36","documentation":"utils.ExpandHomeDir expands a leading tilde (~) in a path to the user's home directory. It only understands '~' or '~/...' (and '~\\...' on Windows); any other form such as '~user/path' or '~foo' cannot be resolved, so it returns this error instead of guessing. It then uses os.UserHomeDir() to do the actual expansion.","triggerScenarios":"ExpandHomeDir(path) is called with a path where path[0] == '~' but path[1] is neither '/' nor '\\\\' and the path is longer than 1 character — e.g. '~otheruser/config.yml', '~foo', or a config value like '~home/file'.","commonSituations":"Config files specifying '~user/...' style paths (supported by shells but not by this helper); typos like '~config' instead of '~/config'; paths copied from examples using ~username expansion.","solutions":["Change the path to use '~/...' (tilde followed by a slash), e.g. '~/.config/wtf/config.yml'.","Use an absolute path (/home/user/...) if you truly need another user's home directory.","Expand the path yourself (via os/user lookup) before passing it to any WTFUtil API that calls ExpandHomeDir."],"exampleFix":"// before\npath := \"~bob/config.yml\" // error: cannot expand user-specific home dir\n\n// after\npath := \"~/config.yml\"        // expands to your own home\n// or\npath := \"/home/bob/config.yml\"","handlingStrategy":"validation","validationCode":"func validateTildePath(p string) error {\n    if strings.HasPrefix(p, \"~\") && !strings.HasPrefix(p, \"~/\") && !strings.HasPrefix(p, \"~\\\\\") && p != \"~\" {\n        return fmt.Errorf(\"unsupported tilde path %q; use '~/...' or an absolute path\", p)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"expanded, err := utils.ExpandHomeDir(path)\nif err != nil {\n    // fall back to the raw path or ask the user for an absolute path\n    return fmt.Errorf(\"path %q: %w\", path, err)\n}","preventionTips":["Use '~/...' (tilde + slash) or absolute paths in config files — never '~username/...'.","Expand '~user' paths yourself via os/user.Lookup before passing them in.","Lint config files for bare-tilde path patterns."],"tags":["filesystem","path","configuration"],"backgroundTag":"invalid-path-format","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"}