{"record":{"id":"e0d911cf1a93ee24","repo":"JanDeDobbeleer/oh-my-posh","slug":"failed-to-get-home-directory","errorCode":null,"errorMessage":"failed to get home directory","messagePattern":"failed to get home directory","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/dsc/shell.go","lineNumber":94,"sourceCode":"\tcontent, err := os.ReadFile(configPath)\n\tif err != nil {\n\t\tlog.Debug(\"failed to read shell config file\")\n\t\treturn err\n\t}\n\n\tcontentStr, updated := s.updateShellConfig(string(content))\n\tif !updated {\n\t\tlog.Debug(\"shell config already up to date, skipping write\")\n\t\treturn nil\n\t}\n\n\treturn os.WriteFile(configPath, []byte(contentStr), 0644)\n}\n\nfunc (s *Shell) getShellConfigPath() (string, error) {\n\thome := path.Home()\n\tif home == \"\" {\n\t\treturn \"\", fmt.Errorf(\"failed to get home directory\")\n\t}\n\n\tswitch s.Name {\n\tcase shell.BASH:\n\t\tbashrc := filepath.Join(home, \".bashrc\")\n\t\tif _, err := os.Stat(bashrc); err == nil {\n\t\t\treturn bashrc, nil\n\t\t}\n\n\t\treturn filepath.Join(home, \".bash_profile\"), nil\n\tcase shell.ZSH:\n\t\treturn filepath.Join(home, \".zshrc\"), nil\n\tcase shell.FISH:\n\t\tconfigDir := filepath.Join(home, \".config\", \"fish\")\n\t\treturn filepath.Join(configDir, \"config.fish\"), nil\n\tcase shell.PWSH:\n\t\treturn cmd.Run(s.Name, \"-NoProfile\", \"-Command\", \"$PROFILE\")\n\tcase shell.NU:","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cli/dsc/shell.go#L76-L112","documentation":"getShellConfigPath returns this error when path.Home() yields an empty string, meaning no home directory could be determined for the current user. Without a home path the shell rc file locations (.bashrc, .zshrc, ...) cannot be computed, so Apply aborts early via the \"failed to get shell config path\" wrapper.","triggerScenarios":"Applying a DSC Shell resource in an environment where HOME is unset (bare container, some CI runners, su without proper env) or where the OS user lookup fails so path.Home() returns \"\".","commonSituations":"Docker containers running as root or a service account without HOME; cron/systemd jobs with a stripped environment; Windows builds where the user profile directory cannot be resolved.","solutions":["Set HOME to the user's home directory before running oh-my-posh (e.g. export HOME=/root or /home/<user>)","Run the command as a normal login user whose home is resolvable (`echo $HOME` should print a non-empty path)","In containers/CI, pass the env explicitly: docker run -e HOME=/root ... or set it in the pipeline env","Check for a typo'd or empty HOME entry in your shell profile or service definition"],"exampleFix":"// before: HOME unset in CI\noh-my-posh dsc apply -f shell.yaml\n// after\nexport HOME=${HOME:-$(getent passwd $(whoami) | cut -d: -f6)}\noh-my-posh dsc apply -f shell.yaml","handlingStrategy":"validation","validationCode":"home, err := os.UserHomeDir()\nif err != nil || home == \"\" {\n    return fmt.Errorf(\"no home directory available: %w\", err)\n}\nif st, serr := os.Stat(home); serr != nil || !st.IsDir() {\n    return fmt.Errorf(\"home %s is not accessible\", home)\n}","typeGuard":null,"tryCatchPattern":"if err := sh.Apply(); err != nil {\n    if strings.Contains(err.Error(), \"home directory\") {\n        return fmt.Errorf(\"set HOME to a valid directory before applying: %w\", err)\n    }\n    return err\n}","preventionTips":["Export HOME explicitly in containers, cron jobs, and CI runners","Use login shells or `su -`/`sudo -i` so the environment includes HOME","Verify `echo $HOME` prints a non-empty, existing path before applying DSC documents","Avoid stripping the environment with `env -i` unless you re-export HOME"],"tags":["environment","home-directory","dsc","shell"],"backgroundTag":"missing-env-var","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}