{"record":{"id":"293d24a97d5baf4d","repo":"golang/go","slug":"missing-user-config-dir","errorCode":null,"errorMessage":"missing user-config dir","messagePattern":"missing user-config dir","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/cfg/cfg.go","lineNumber":361,"sourceCode":"\tm      map[string]string\n\tgoroot map[string]string\n}\n\n// EnvFile returns the name of the Go environment configuration file,\n// and reports whether the effective value differs from the default.\nfunc EnvFile() (string, bool, error) {\n\tif file := os.Getenv(\"GOENV\"); file != \"\" {\n\t\tif file == \"off\" {\n\t\t\treturn \"\", false, fmt.Errorf(\"GOENV=off\")\n\t\t}\n\t\treturn file, true, nil\n\t}\n\tdir, err := os.UserConfigDir()\n\tif err != nil {\n\t\treturn \"\", false, err\n\t}\n\tif dir == \"\" {\n\t\treturn \"\", false, fmt.Errorf(\"missing user-config dir\")\n\t}\n\treturn filepath.Join(dir, \"go/env\"), false, nil\n}\n\nfunc initEnvCache() {\n\tenvCache.m = make(map[string]string)\n\tenvCache.goroot = make(map[string]string)\n\tif file, _, _ := EnvFile(); file != \"\" {\n\t\treadEnvFile(file, \"user\")\n\t}\n\tgoroot := findGOROOT(envCache.m[\"GOROOT\"])\n\tif goroot != \"\" {\n\t\treadEnvFile(filepath.Join(goroot, \"go.env\"), \"GOROOT\")\n\t}\n\n\t// Save the goroot for func init calling SetGOROOT,\n\t// and also overwrite anything that might have been in go.env.\n\t// It makes no sense for GOROOT/go.env to specify","sourceCodeStart":343,"sourceCodeEnd":379,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/cfg/cfg.go#L343-L379","documentation":"Returned by cfg.EnvFile() when GOENV is unset, os.UserConfigDir() succeeds, but returns an empty string — there is no usable user-config directory to host the go/env file. Distinct from a UserConfigDir error (which is propagated verbatim): here the platform API gave a meaningless empty result.","triggerScenarios":"GOENV unset; os.UserConfigDir() returns (\"\", nil) — possible on minimal/embedded platforms or when the config-dir resolver finds nothing but does not error.","commonSituations":"Stripped-down containers, embedded targets, or custom builds where the config directory resolver yields empty; misconfigured HOME/XDG_CONFIG_HOME that resolves to an empty value.","solutions":["Set GOENV explicitly to a writable file path.","Set HOME / XDG_CONFIG_HOME so UserConfigDir returns a real directory.","Set GOENV=off if the env file is not needed at all."],"exampleFix":"# before\n$ go env   # missing user-config dir\n\n# after\n$ export GOENV=$HOME/.config/go/env\n$ go env","handlingStrategy":"validation","validationCode":"if os.Getenv(\"GOENV\") == \"\" {\n    if d, _ := os.UserConfigDir(); d == \"\" {\n        _ = os.Setenv(\"GOENV\", filepath.Join(os.TempDir(), \"go-env\"))\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set HOME / XDG_CONFIG_HOME in minimal containers.","Or set GOENV to a concrete writable path.","Or set GOENV=off if the env file is not needed."],"tags":["configuration","environment","goenv"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}