{"record":{"id":"0639695bc9092a0c","repo":"chenhg5/cc-connect","slug":"cannot-resolve-home-directory-w","errorCode":null,"errorMessage":"cannot resolve home directory: %w","messagePattern":"cannot resolve home directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/engine.go","lineNumber":16979,"sourceCode":"\treturn false\n}\n\nfunc looksLikeGitURL(s string) bool {\n\treturn strings.HasPrefix(s, \"https://\") ||\n\t\tstrings.HasPrefix(s, \"http://\") ||\n\t\tstrings.HasPrefix(s, \"git@\") ||\n\t\tstrings.HasPrefix(s, \"ssh://\")\n}\n\n// resolveLocalDirPath resolves a user-provided directory path to an absolute\n// path, expanding ~/... and joining relative paths with baseDir. It rejects\n// paths that escape baseDir via ../ traversal.\nfunc resolveLocalDirPath(target, baseDir string) (string, error) {\n\tdirPath := target\n\tif dirPath == \"~\" || strings.HasPrefix(dirPath, \"~/\") {\n\t\thome, err := os.UserHomeDir()\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"cannot resolve home directory: %w\", err)\n\t\t}\n\t\tdirPath = filepath.Join(home, dirPath[2:])\n\t} else if !filepath.IsAbs(dirPath) {\n\t\tdirPath = filepath.Join(baseDir, dirPath)\n\t}\n\tcleaned := filepath.Clean(dirPath)\n\tresolved, err := filepath.EvalSymlinks(cleaned)\n\tif err != nil {\n\t\tresolved = cleaned\n\t}\n\tif baseDir != \"\" && !filepath.IsAbs(target) && !strings.HasPrefix(target, \"~\") {\n\t\tcleanBase := filepath.Clean(baseDir)\n\t\tif evalBase, err := filepath.EvalSymlinks(cleanBase); err == nil {\n\t\t\tcleanBase = evalBase\n\t\t}\n\t\tif !strings.HasPrefix(resolved, cleanBase+string(filepath.Separator)) && resolved != cleanBase {\n\t\t\treturn \"\", fmt.Errorf(\"path escapes workspace base directory\")\n\t\t}","sourceCodeStart":16961,"sourceCodeEnd":16997,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/engine.go#L16961-L16997","documentation":"resolveLocalDirPath wraps os.UserHomeDir failures with this error when the target path starts with '~' or '~/'. The home directory cannot be determined because the environment provides no usable HOME (or equivalent) value, so the tilde path cannot be expanded.","triggerScenarios":"Calling resolveLocalDirPath with target == \"~\" or a \"~/...\" path while os.UserHomeDir() returns an error — typically because $HOME is unset/empty (Linux) or the user profile cannot be resolved (Windows).","commonSituations":"Running the daemon under systemd with a minimal environment lacking HOME; running in a container or cron job where HOME is not set; SSH non-login shells with stripped environment.","solutions":["Set the HOME environment variable for the process (e.g. Environment=HOME=/home/user in the systemd unit)","Replace the ~/ prefix in the configured path with an absolute path","Run the service as a normal login user so the home directory resolves","Use the daemon's baseDir-relative path instead of a tilde path"],"exampleFix":"// before (config.toml)\nworkspaceDir = \"~/projects/repo\"\n// after\nworkspaceDir = \"/home/alice/projects/repo\"","handlingStrategy":"validation","validationCode":"if os.Getenv(\"HOME\") == \"\" {\n    return fmt.Errorf(\"HOME is not set; tilde paths cannot be resolved\")\n}","typeGuard":null,"tryCatchPattern":"path, err := resolveLocalDirPath(target, baseDir)\nif err != nil && strings.Contains(err.Error(), \"cannot resolve home directory\") {\n    slog.Warn(\"HOME unset; expand tilde manually or use absolute path\", \"err\", err)\n    return err\n}","preventionTips":["Always set HOME in service units (systemd: Environment=HOME=%h)","Prefer absolute paths over ~/ in daemon configs","Validate config paths resolve at startup, not at first use","Run daemons as a normal user with a defined home directory"],"tags":["home-directory","path-resolution","environment"],"backgroundTag":"missing-env-var","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}