{"record":{"id":"b245d4013659ef71","repo":"golang/go","slug":"file-incomplete","errorCode":null,"errorMessage":"file incomplete","messagePattern":"file incomplete","errorType":"exception","errorClass":"entryNotFoundError","httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/cache/cache.go","lineNumber":276,"sourceCode":"\tc.markUsed(c.fileName(id, \"a\"))\n\n\treturn Entry{buf, size, time.Unix(0, tm)}, nil\n}\n\n// GetFile looks up the action ID in the cache and returns\n// the name of the corresponding data file.\nfunc GetFile(c Cache, id ActionID) (file string, entry Entry, err error) {\n\tentry, err = c.Get(id)\n\tif err != nil {\n\t\treturn \"\", Entry{}, err\n\t}\n\tfile = c.OutputFile(entry.OutputID)\n\tinfo, err := os.Stat(file)\n\tif err != nil {\n\t\treturn \"\", Entry{}, &entryNotFoundError{Err: err}\n\t}\n\tif info.Size() != entry.Size {\n\t\treturn \"\", Entry{}, &entryNotFoundError{Err: errors.New(\"file incomplete\")}\n\t}\n\treturn file, entry, nil\n}\n\n// GetBytes looks up the action ID in the cache and returns\n// the corresponding output bytes.\n// GetBytes should only be used for data that can be expected to fit in memory.\nfunc GetBytes(c Cache, id ActionID) ([]byte, Entry, error) {\n\tentry, err := c.Get(id)\n\tif err != nil {\n\t\treturn nil, entry, err\n\t}\n\tdata, _ := os.ReadFile(c.OutputFile(entry.OutputID))\n\tif sha256.Sum256(data) != entry.OutputID {\n\t\treturn nil, entry, &entryNotFoundError{Err: errors.New(\"bad checksum\")}\n\t}\n\treturn data, entry, nil\n}","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/cache/cache.go#L258-L294","documentation":"In GetFile(), after successfully reading the entry metadata via c.Get(id), the actual output data file on disk has a different size than what the entry header declares (entry.Size). The output file was truncated or extended after the entry was written. This is a post-metadata integrity check on the output data file specifically.","triggerScenarios":"GetFile(c, id) calls c.Get(id) successfully to obtain the Entry, then os.Stat(file) returns file info whose Size() != entry.Size. The file path comes from c.OutputFile(entry.OutputID).","commonSituations":"Output file truncated by a crash or power loss during the write of the output data; disk full condition after the metadata was written but before the output completed; external process (backup sync, antivirus) truncated the output file; filesystem inconsistency.","solutions":["Run go clean -cache to remove entries whose output files are inconsistent","Check disk space on the GOCACHE partition (df -h)","Verify no external tool modifies cache output files","Run filesystem integrity checks"],"exampleFix":"// before: output file size mismatch\n// $ go build ./... # fails with 'cache entry not found: file incomplete'\n\n// after: clean cache\n// $ go clean -cache && go build ./...","handlingStrategy":"try-catch","validationCode":"// Before using a cached output file, verify it exists and has the expected size.\nfunc validateOutputFile(path string, expectedSize int64) error {\n    info, err := os.Stat(path)\n    if err != nil {\n        return err\n    }\n    if info.Size() != expectedSize {\n        return fmt.Errorf(\"output file %s is %d bytes, expected %d\", path, info.Size(), expectedSize)\n    }\n    return nil\n}","typeGuard":"func isFileIncomplete(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"file incomplete\")\n}","tryCatchPattern":"// file, entry, err := cache.GetFile(c, id)\n// if err != nil {\n//     // File incomplete — output data file is truncated.\n//     // Treat as miss and rebuild.\n//     output = rebuild()\n// }","preventionTips":["Ensure sufficient disk space during builds to prevent truncated output writes","Avoid interrupting builds mid-compilation","Exclude GOCACHE from backup/sync tools that may truncate files","Run go clean -cache if output files are consistently incomplete"],"tags":["go","build-cache","corruption","disk-cache","output-file"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}