{"record":{"id":"54add4b987cc26d9","repo":"golang/go","slug":"loading-cached-file-s-w","errorCode":null,"errorMessage":"loading cached file %s: %w","messagePattern":"loading cached file (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/work/exec.go","lineNumber":1024,"sourceCode":"\t\treturn b.Shell(a).reportCmd(\"\", \"\", msg, err)\n\t}\n\treturn nil\n}\n\nfunc (b *Builder) cacheObjdirFile(a *Action, c cache.Cache, name string) error {\n\tf, err := os.Open(a.Objdir + name)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer f.Close()\n\t_, _, err = c.Put(cache.Subkey(a.actionID, name), f)\n\treturn err\n}\n\nfunc (b *Builder) findCachedObjdirFile(a *Action, c cache.Cache, name string) (string, error) {\n\tfile, _, err := cache.GetFile(c, cache.Subkey(a.actionID, name))\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"loading cached file %s: %w\", name, err)\n\t}\n\treturn file, nil\n}\n\nfunc (b *Builder) loadCachedObjdirFile(a *Action, c cache.Cache, name string) error {\n\tcached, err := b.findCachedObjdirFile(a, c, name)\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn b.Shell(a).CopyFile(a.Objdir+name, cached, 0666, true)\n}\n\nfunc (b *Builder) cacheSrcFiles(a *Action, srcfiles []string) {\n\tc := cache.Default()\n\tvar buf bytes.Buffer\n\tfor _, file := range srcfiles {\n\t\tif !strings.HasPrefix(file, a.Objdir) {\n\t\t\t// not generated","sourceCodeStart":1006,"sourceCodeEnd":1042,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/work/exec.go#L1006-L1042","documentation":"On the build-cache hit path, findCachedObjdirFile calls cache.GetFile to restore an intermediate object-directory file (e.g. a generated _cgo_*.go) keyed by a subkey of the action ID. If the cache lookup fails, the file's logical name and the wrapped error are returned. The cause is usually a missing, corrupted, or inaccessible cache entry.","triggerScenarios":"Fires in findCachedObjdirFile when cache.GetFile(c, cache.Subkey(a.actionID, name)) returns an error, during a cache-hit rebuild that needs to restore objdir artifacts.","commonSituations":"Cache corruption from concurrent builds sharing one GOCACHE, a full disk, eviction mid-build, a GOCACHE path on a flaky network filesystem, or stale permissions on the cache directory.","solutions":["Run `go clean -cache` and rebuild","Verify GOCACHE points to a writable local directory with free space","Ensure no concurrent go build processes write the same cache","Check filesystem permissions on the cache directory"],"exampleFix":"// before (stale/corrupt cache)\ngo build ./...\n// after\ngo clean -cache && go build ./...","handlingStrategy":"retry","validationCode":"// Verify the cache dir is writable and has space before building\ncacheDir := os.Getenv(\"GOCACHE\")\nif fi, err := os.Stat(cacheDir); err != nil || !fi.IsDir() {\n    return fmt.Errorf(\"GOCACHE unavailable: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"// On a cache-read error, clean and retry once\nout, err := cmd.CombinedOutput()\nif err != nil && bytes.Contains(out, []byte(\"loading cached file\")) {\n    exec.Command(\"go\", \"clean\", \"-cache\").Run()\n    out, err = cmd.CombinedOutput()\n}","preventionTips":["Point GOCACHE at a dedicated fast local disk","Never run concurrent builds against the same cache directory","Monitor free space on the cache partition","Avoid NFS/FUSE for GOCACHE"],"tags":["go-toolchain","build-cache","io","cache-miss"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}