{"record":{"id":"18ca5ddac4ad36b6","repo":"abiosoft/colima","slug":"error-retrieving-home-directory-w","errorCode":null,"errorMessage":"error retrieving home directory: %w","messagePattern":"error retrieving home directory: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"util/util.go","lineNumber":20,"sourceCode":"\nimport (\n\t\"fmt\"\n\t\"net\"\n\t\"os\"\n\t\"os/exec\"\n\t\"path/filepath\"\n\t\"strings\"\n\n\t\"github.com/google/shlex\"\n\t\"github.com/sirupsen/logrus\"\n)\n\n// HomeDir returns the user home directory.\nfunc HomeDir() string {\n\thome, err := os.UserHomeDir()\n\tif err != nil {\n\t\t// this should never happen\n\t\tlogrus.Fatal(fmt.Errorf(\"error retrieving home directory: %w\", err))\n\t}\n\treturn home\n}\n\n// RandomAvailablePort returns an available port on the host machine.\nfunc RandomAvailablePort() int {\n\tlistener, err := net.Listen(\"tcp\", \":0\")\n\tif err != nil {\n\t\tlogrus.Fatal(fmt.Errorf(\"error picking an available port: %w\", err))\n\t}\n\n\tif err := listener.Close(); err != nil {\n\t\tlogrus.Fatal(fmt.Errorf(\"error closing temporary port listener: %w\", err))\n\t}\n\n\treturn listener.Addr().(*net.TCPAddr).Port\n}\n","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/util/util.go#L2-L38","documentation":"HomeDir (util/util.go:20) wraps os.UserHomeDir and calls logrus.Fatal on failure, so this is not a returned error — the process prints the message and exits immediately. On Unix, os.UserHomeDir reads only the $HOME environment variable, so it fails exactly when $HOME is unset or empty. colima resolves nearly everything (~ paths, config dirs) through HomeDir, so any entry point can trigger the exit.","triggerScenarios":"Running colima with a sanitized environment: `env -i colima ...`, cron/systemd/launchd jobs that don't inherit HOME, minimal containers, or `HOME= colima start`.","commonSituations":"Automation in CI images that strip env; Docker containers without USER/HOME set; sudo -i edge cases where HOME points at a missing dir; scripts that unset variables before invoking colima.","solutions":["Set HOME before invoking colima: `HOME=/Users/me colima start`","For services (systemd/launchd), add Environment=\"HOME=/Users/me\" or an EnvironmentFile with HOME","In containers, set a valid USER/HOME or export HOME=/root","Prefer invoking colima from a login shell when possible"],"exampleFix":"# before (cron/systemd: HOME unset -> colima exits immediately)\nexec colima start\n\n# after\nEnvironment=\"HOME=/Users/me\"\nExecStart=/opt/homebrew/bin/colima start","handlingStrategy":"validation","validationCode":"// fail with a clear message before colima's logrus.Fatal does\nif os.Getenv(\"HOME\") == \"\" {\n    log.Fatal(\"HOME is unset — set it (export HOME=/Users/me) before running colima\")\n}","typeGuard":null,"tryCatchPattern":"// no catch possible: logrus.Fatal exits the process.\n// Only defense is ensuring HOME is set in every invocation context\n// (cron lines, systemd units, Docker ENV, launchd plists).","preventionTips":["Always set HOME explicitly in service definitions and containers","Add `HOME=${HOME:-/root}` guards at the top of wrapper scripts","Test automation with `env -i` to surface missing-env failures early"],"tags":["environment","home","fatal","process-exit"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}