{"record":{"id":"ab02b2719662c96f","repo":"golang/go","slug":"gomodcache-entry-is-relative-must-be-absolute-pat","errorCode":null,"errorMessage":"GOMODCACHE entry is relative; must be absolute path: %q","messagePattern":"GOMODCACHE entry is relative; must be absolute path: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/envcmd/env.go","lineNumber":675,"sourceCode":"\t// invalid value, the next cmd/go invocation might fail immediately,\n\t// even 'go env -w' itself.\n\tswitch key {\n\tcase \"GO111MODULE\":\n\t\tswitch val {\n\t\tcase \"\", \"auto\", \"on\", \"off\":\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"invalid %s value %q\", key, val)\n\t\t}\n\tcase \"GOPATH\":\n\t\tif strings.HasPrefix(val, \"~\") {\n\t\t\treturn fmt.Errorf(\"GOPATH entry cannot start with shell metacharacter '~': %q\", val)\n\t\t}\n\t\tif !filepath.IsAbs(val) && val != \"\" {\n\t\t\treturn fmt.Errorf(\"GOPATH entry is relative; must be absolute path: %q\", val)\n\t\t}\n\tcase \"GOMODCACHE\":\n\t\tif !filepath.IsAbs(val) && val != \"\" {\n\t\t\treturn fmt.Errorf(\"GOMODCACHE entry is relative; must be absolute path: %q\", val)\n\t\t}\n\tcase \"CC\", \"CXX\":\n\t\tif val == \"\" {\n\t\t\tbreak\n\t\t}\n\t\targs, err := quoted.Split(val)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"invalid %s: %v\", key, err)\n\t\t}\n\t\tif len(args) == 0 {\n\t\t\treturn fmt.Errorf(\"%s entry cannot contain only space\", key)\n\t\t}\n\t\tif !filepath.IsAbs(args[0]) && args[0] != filepath.Base(args[0]) {\n\t\t\treturn fmt.Errorf(\"%s entry is relative; must be absolute path: %q\", key, args[0])\n\t\t}\n\t}\n\n\tif !utf8.ValidString(val) {","sourceCodeStart":657,"sourceCodeEnd":693,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/envcmd/env.go#L657-L693","documentation":"Returned by checkEnvWrite when GOMODCACHE is non-empty and not absolute. GOMODCACHE points at the downloaded-module cache and must be absolute so cache lookups are stable regardless of the go command's working directory.","triggerScenarios":"`go env -w GOMODCACHE=./cache`, `go env -w GOMODCACHE=modcache`, or any non-empty relative value.","commonSituations":"Users trying to scope the module cache per-project; CI runners with relative cache directories; misconfigured GOPATH-relative defaults from custom setup scripts.","solutions":["Use an absolute path: `go env -w GOMODCACHE=$HOME/go/pkg/mod`.","Leave GOMODCACHE unset so it defaults to GOPATH[0]/pkg/mod.","For project-scoped caches, set GOMODCACHE in the OS env to an absolute per-project directory."],"exampleFix":"# before\n$ go env -w GOMODCACHE=./modcache\nerror: GOMODCACHE entry is relative; must be absolute path\n# after\n$ go env -w GOMODCACHE=\"$HOME/.cache/go-mod\"","handlingStrategy":"validation","validationCode":"func ensureAbs(v string) (string, error) {\n    if v == \"\" || filepath.IsAbs(v) { return v, nil }\n    return filepath.Abs(v)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Leave GOMODCACHE unset when the default is acceptable.","Resolve cache paths to absolute before writing.","Use OS env for per-project caches with absolute directories."],"tags":["config","env","gomodcache","validation","filesystem"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}