{"record":{"id":"2e1232a62044d0cb","repo":"golang/go","slug":"error-adding-target-to-cache-w","errorCode":null,"errorMessage":"error adding target to cache: %w","messagePattern":"error adding target to cache: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/work/action.go","lineNumber":519,"sourceCode":"\ta.built = a.Target\n\n\tif !cfg.BuildN {\n\t\t// Cache the output.\n\t\t//\n\t\t// N.B. We don't use updateBuildID here, as preprocessed PGO profiles\n\t\t// do not contain a build ID. updateBuildID is typically responsible\n\t\t// for adding to the cache, thus we must do so ourselves instead.\n\n\t\tr, err := os.Open(a.Target)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error opening target for caching: %w\", err)\n\t\t}\n\n\t\tc := cache.Default()\n\t\toutputID, _, err := c.Put(a.actionID, r)\n\t\tr.Close()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error adding target to cache: %w\", err)\n\t\t}\n\t\tif cfg.BuildX {\n\t\t\tsh.ShowCmd(\"\", \"%s # internal\", joinUnambiguously(str.StringList(\"cp\", a.Target, c.OutputFile(outputID))))\n\t\t}\n\t}\n\n\treturn nil\n}\n\ntype coverProvider struct {\n\t// name of static metadata file fragment emitted by the cover\n\t// tool as part of the package cover action, for selected\n\t// \"go test -cover\" runs.\n\tcovMetaFileName string\n\n\t// coverageConfig is the path to the json-serialized covcmd.CoverPkgConfig\n\t// provided to the cover tool. The config is created by coverConfig.\n\tcoverageConfig string","sourceCodeStart":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/work/action.go#L501-L537","documentation":"After successfully opening the preprocessed PGO target, pgoActor.Act calls cache.Default().Put to store it under the action ID. If the cache's Put returns an error (disk full, cache dir unwritable, hash mismatch), it is wrapped and returned.","triggerScenarios":"PGO profile caching fails due to GOCACHE being read-only, full, on a corrupted index, or hit by an OS-level quota. Distinct from 1167: the file was opened fine, the cache write itself failed.","commonSituations":"CI containers with small tmpfs for GOCACHE; user ran 'chmod -R a-w' on the cache; disk quota exceeded; concurrent cache eviction racing with the Put.","solutions":["Run 'go clean -cache' to reset the cache index.","Point GOCACHE at a directory on a volume with adequate free space and write permission.","Check 'df -h' and 'quota' for the cache volume.","If reproducible, run with GODEBUG=gocachehash=1 to diagnose cache write failures."],"exampleFix":"// before\n$ go build -pgoprofile=cpu.pprof ./...\n// error: error adding target to cache: write /small-tmpfs/...: no space left on device\n\n// after\n$ export GOCACHE=$HOME/.cache/go-build\n$ go clean -cache\n$ go build -pgoprofile=cpu.pprof ./...","handlingStrategy":"validation","validationCode":"// Ensure the cache dir is writable and has space before building.\nfunc checkCacheWritable(dir string) error {\n    f, err := os.CreateTemp(dir, \".probe\")\n    if err != nil { return fmt.Errorf(\"cache not writable: %w\", err) }\n    _ = f.Close()\n    _ = os.Remove(f.Name())\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Allocate adequate space for GOCACHE (multi-GB).","Run 'go clean -cache' periodically.","Don't chmod the cache read-only; don't run builds as mismatched users."],"tags":["pgo","build-cache","io","profile"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}