{"record":{"id":"bf8a03b877a3eb8f","repo":"golang/go","slug":"gocache-is-not-an-absolute-path","errorCode":null,"errorMessage":"GOCACHE is not an absolute path","messagePattern":"GOCACHE is not an absolute path","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/cache/default.go","lineNumber":99,"sourceCode":"\t\t// Compute default location.\n\t\tdir, err := os.UserCacheDir()\n\t\tif err != nil {\n\t\t\tdefaultDir = \"off\"\n\t\t\tdefaultDirErr = fmt.Errorf(\"GOCACHE is not defined and %v\", err)\n\t\t} else {\n\t\t\tdefaultDir = filepath.Join(dir, \"go-build\")\n\t\t}\n\n\t\tnewDir := cfg.Getenv(\"GOCACHE\")\n\t\tif newDir != \"\" {\n\t\t\tdefaultDirErr = nil\n\t\t\tdefaultDirChanged = newDir != defaultDir\n\t\t\tdefaultDir = newDir\n\t\t\tif filepath.IsAbs(defaultDir) || defaultDir == \"off\" {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tdefaultDir = \"off\"\n\t\t\tdefaultDirErr = fmt.Errorf(\"GOCACHE is not an absolute path\")\n\t\t\treturn\n\t\t}\n\t})\n\n\treturn defaultDir, defaultDirChanged, defaultDirErr\n}\n","sourceCodeStart":81,"sourceCodeEnd":106,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/cache/default.go#L81-L106","documentation":"Returned by cache.DefaultDir() when GOCACHE is set to a non-empty value that is neither absolute nor the literal \"off\". A relative cache path is rejected because subprocesses and tool invocations resolve relative paths against differing working directories, which would scatter cache files unpredictably.","triggerScenarios":"GOCACHE=relative/path or GOCACHE=./go-build (anything not starting with / on Unix or a drive on Windows, and not \"off\").","commonSituations":"Makefiles/scripts exporting a relative GOCACHE; CI config with `GOCACHE: build-cache`; users trying to keep the cache inside the project tree with a relative path.","solutions":["Use an absolute path: resolve with realpath/$(pwd) before exporting GOCACHE.","Or set GOCACHE=off to disable caching explicitly.","In scripts, write `export GOCACHE=\"$PWD/.go-cache\"` instead of a relative value."],"exampleFix":"# before\nexport GOCACHE=build-cache   # -> GOCACHE is not an absolute path\n\n# after\nexport GOCACHE=\"$PWD/build-cache\"","handlingStrategy":"validation","validationCode":"if v := os.Getenv(\"GOCACHE\"); v != \"\" && v != \"off\" && !filepath.IsAbs(v) {\n    abs, _ := filepath.Abs(v)\n    _ = os.Setenv(\"GOCACHE\", abs)\n}","typeGuard":"func isUsableGocache(v string) bool {\n    return v == \"off\" || filepath.IsAbs(v)\n}","tryCatchPattern":null,"preventionTips":["Export GOCACHE as an absolute path in scripts (use $PWD).","Add a CI check that `go env GOCACHE` is absolute or 'off'.","Avoid relative cache paths in Makefiles."],"tags":["cache","configuration","path","gocache"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}