{"record":{"id":"734265fb4329519f","repo":"alibaba/open-code-review","slug":"cannot-determine-home-directory-w","errorCode":null,"errorMessage":"cannot determine home directory: %w","messagePattern":"cannot determine home directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/config_cmd.go","lineNumber":95,"sourceCode":"\tShort: \"Interactive model selection\",\n\tArgs:  cobra.NoArgs,\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\treturn runConfigModel()\n\t},\n}\n\nfunc init() {\n\tconfigCmd.AddCommand(configSetCmd)\n\tconfigCmd.AddCommand(configUnsetCmd)\n\tconfigCmd.AddCommand(configProviderCmd)\n\tconfigCmd.AddCommand(configModelCmd)\n}\n\n// Default config file location: ~/.opencodereview/config.json\nfunc defaultConfigPath() (string, error) {\n\thome, err := os.UserHomeDir()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"cannot determine home directory: %w\", err)\n\t}\n\treturn filepath.Join(home, \".opencodereview\", \"config.json\"), nil\n}\n\n// resolveConfigPath returns OCR_CONFIG_PATH when set, otherwise the default user config path.\n// Intentionally used only by read-only commands (e.g. ocr llm test). Write paths such as\n// config set and review keep defaultConfigPath() so a leaked OCR_CONFIG_PATH cannot redirect writes.\nfunc resolveConfigPath() (string, error) {\n\tif p := strings.TrimSpace(os.Getenv(\"OCR_CONFIG_PATH\")); p != \"\" {\n\t\treturn p, nil\n\t}\n\treturn defaultConfigPath()\n}\n\nfunc runConfigSet(key, value string) error {\n\tconfigPath, err := defaultConfigPath()\n\tif err != nil {\n\t\treturn err","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/config_cmd.go#L77-L113","documentation":"defaultConfigPath builds the default config location ~/.opencodereview/config.json using os.UserHomeDir(). This error wraps the failure of that lookup. os.UserHomeDir fails when neither $HOME (Unix) nor %USERPROFILE% (Windows) is set, so the tool cannot know where to place the config file.","triggerScenarios":"Running `ocr config set/unset` (which call defaultConfigPath) in an environment where HOME is unset — cron jobs, systemd units, Docker containers running as non-root without ENV HOME, stripped-down CI runners, or SSH with a malformed environment.","commonSituations":"Dockerfile missing `ENV HOME=/root`; running ocr under a service account whose passwd entry lacks a home; `sudo -u app` without preserving HOME; minimal Alpine/busybox containers; CI jobs running with `env -i`.","solutions":["Set HOME explicitly: `export HOME=/home/<user>` (or `ENV HOME=/root` in the Dockerfile) before running ocr.","Note: `ocr config set` intentionally ignores OCR_CONFIG_PATH for writes, so setting that env var will not help here — fix HOME instead.","For read-only commands, OCR_CONFIG_PATH can bypass the home lookup: `OCR_CONFIG_PATH=/etc/ocr/config.json ocr llm test`.","Verify the environment: `env | grep ^HOME=` and check the service user's passwd entry (`getent passwd <user>`)."],"exampleFix":"// before (Dockerfile)\nRUN ocr config set provider anthropic\n// after (Dockerfile)\nENV HOME=/root\nRUN ocr config set provider anthropic","handlingStrategy":"fallback","validationCode":"// shell: ensure HOME is resolvable before invoking ocr config write commands\n[ -n \"${HOME:-}\" ] || { echo \"HOME is not set\"; exit 1; }\n# or for read-only commands, pin the path:\nexport OCR_CONFIG_PATH=\"${OCR_CONFIG_PATH:-$HOME/.opencodereview/config.json}\"","typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"ocr\", \"config\", \"set\", key, val).CombinedOutput()\nif err != nil && strings.Contains(string(out), \"cannot determine home directory\") {\n\tcmd.Env = append(os.Environ(), \"HOME=/tmp/ocr-home\") // retry with explicit HOME\n}","preventionTips":["Set ENV HOME in Dockerfiles and systemd units that run ocr.","Avoid `env -i` or `sudo -u` without preserving HOME for ocr commands.","Remember OCR_CONFIG_PATH does not redirect config set/unset writes — HOME must be valid.","In CI, assert `test -n \"$HOME\"` in the setup step."],"tags":["cli","environment","home-directory"],"backgroundTag":"missing-env-var","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}