{"record":{"id":"5cad718e28769192","repo":"hasura/graphql-engine","slug":"cannot-get-home-directory-w","errorCode":null,"errorMessage":"cannot get home directory: %w","messagePattern":"cannot get home directory: %w","errorType":"exception","errorClass":"errors.Error","httpStatus":null,"severity":"error","filePath":"cli/global_config.go","lineNumber":121,"sourceCode":"\terr = os.WriteFile(filename, b, 0o644)\n\tif err != nil {\n\t\treturn errors.E(op, fmt.Errorf(\"write file: %w\", err))\n\t}\n\n\treturn nil\n}\n\n// setupGlobConfig ensures that global config directory and file exists and\n// reads it into the GlobalConfig object.\nfunc (ec *ExecutionContext) setupGlobalConfig() error {\n\tvar op errors.Op = \"cli.ExecutionContext.setupGlobalConfig\"\n\t// check if the directory name is set, else default\n\tif len(ec.GlobalConfigDir) == 0 {\n\t\tec.Logger.Debug(\"global config directory is not pre-set, defaulting\")\n\n\t\thome, err := os.UserHomeDir()\n\t\tif err != nil {\n\t\t\treturn errors.E(op, fmt.Errorf(\"cannot get home directory: %w\", err))\n\t\t}\n\n\t\tglobalConfigDir := filepath.Join(home, GlobalConfigDirName)\n\t\tec.GlobalConfigDir = globalConfigDir\n\t\tec.Logger.Debugf(\"global config directory set as '%s'\", ec.GlobalConfigDir)\n\t}\n\n\t// create the config directory\n\terr := os.MkdirAll(ec.GlobalConfigDir, os.ModePerm)\n\tif err != nil {\n\t\treturn errors.E(op, fmt.Errorf(\"cannot create global config directory: %w\", err))\n\t}\n\n\t// check if the filename is set, else default\n\tif len(ec.GlobalConfigFile) == 0 {\n\t\tec.GlobalConfigFile = filepath.Join(ec.GlobalConfigDir, GlobalConfigFileName)\n\t\tec.Logger.Debugf(\"global config file set as '%s'\", ec.GlobalConfigFile)\n\t}","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/global_config.go#L103-L139","documentation":"setupGlobalConfig calls os.UserHomeDir() to derive the default global config directory (~/.<GlobalConfigDirName>) and the OS/environment could not provide a home directory. On Unix this happens when $HOME is empty or unset; on Windows when %USERPROFILE% is unavailable. The error wraps the underlying syscall/env lookup failure.","triggerScenarios":"Running the CLI with HOME unset or empty (common in minimal Docker scratch/alpine images, systemd services, CI runners, or `sudo -E` stripping env) so len(ec.GlobalConfigDir) == 0 forces the UserHomeDir lookup to fail.","commonSituations":"Docker containers without an explicit HOME env var, Kubernetes pods running as a nonexist­ent UID with no HOME, CI pipelines, or running under a service manager that does not set user environment variables.","solutions":["Set HOME explicitly in the environment (docker ENV HOME=/root or export HOME=$PWD)","Pre-set ec.GlobalConfigDir before calling Prepare so the home lookup is skipped entirely","Run as a user with a valid passwd entry / USERPROFILE on Windows","For services, set Environment=HOME=... in the unit file"],"exampleFix":"# before\ndocker run mycli ...\n# after\ndocker run -e HOME=/tmp mycli ...","handlingStrategy":"validation","validationCode":"if ec.GlobalConfigDir == \"\" {\n    if home, err := os.UserHomeDir(); err != nil {\n        ec.GlobalConfigDir = filepath.Join(os.TempDir(), GlobalConfigDirName)\n    } else {\n        ec.GlobalConfigDir = filepath.Join(home, GlobalConfigDirName)\n    }\n}","typeGuard":"func hasHomeDir() bool {\n    if h := os.Getenv(\"HOME\"); h != \"\" {\n        return true\n    }\n    _, err := os.UserHomeDir()\n    return err == nil\n}","tryCatchPattern":"if err := ec.Prepare(ctx); err != nil {\n    if strings.Contains(err.Error(), \"cannot get home directory\") {\n        ec.GlobalConfigDir = filepath.Join(os.TempDir(), GlobalConfigDirName)\n        return ec.Prepare(ctx)\n    }\n    return err\n}","preventionTips":["Always set HOME explicitly in Dockerfiles and systemd units","Pre-set GlobalConfigDir in embedded/programmatic usage to skip the lookup","Fail fast with a clear message when HOME is missing rather than deep in Prepare"],"tags":["go","environment","home-directory","config","docker"],"backgroundTag":"missing-home-directory-env","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}