{"record":{"id":"431a2186e4d6259d","repo":"golang/go","slug":"negative-timestamp","errorCode":null,"errorMessage":"negative timestamp","messagePattern":"negative timestamp","errorType":"exception","errorClass":"entryNotFoundError","httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/cache/cache.go","lineNumber":255,"sourceCode":"\ti := 0\n\tfor i < len(esize) && esize[i] == ' ' {\n\t\ti++\n\t}\n\tsize, err := strconv.ParseInt(string(esize[i:]), 10, 64)\n\tif err != nil {\n\t\treturn missing(fmt.Errorf(\"parsing size: %v\", err))\n\t} else if size < 0 {\n\t\treturn missing(errors.New(\"negative size\"))\n\t}\n\ti = 0\n\tfor i < len(etime) && etime[i] == ' ' {\n\t\ti++\n\t}\n\ttm, err := strconv.ParseInt(string(etime[i:]), 10, 64)\n\tif err != nil {\n\t\treturn missing(fmt.Errorf(\"parsing timestamp: %v\", err))\n\t} else if tm < 0 {\n\t\treturn missing(errors.New(\"negative timestamp\"))\n\t}\n\n\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}","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/cache/cache.go#L237-L273","documentation":"The timestamp field in the cache entry header parsed as a valid integer but is negative. The timestamp represents nanoseconds since Unix epoch and must be non-negative. The entry format space-pads the timestamp to 20 bytes; after stripping spaces and parsing, a negative value indicates corruption in the timestamp portion.","triggerScenarios":"DiskCache.get(id) parses the 20-byte space-padded timestamp field (etime) with strconv.ParseInt(s, 10, 64) after stripping leading spaces. The parse succeeds but tm < 0.","commonSituations":"Byte-level corruption in the timestamp field region of the entry file; storage errors affecting specific sectors; cache format incompatibility from mixing Go versions.","solutions":["Run go clean -cache to purge corrupt entries","Run hardware diagnostics (memtest, disk SMART) if corruption recurs","Ensure consistent Go version across all builds sharing the cache","Check filesystem integrity"],"exampleFix":"// before: corrupt timestamp field in cache entry\n// $ go build ./... # fails with 'cache entry not found: negative timestamp'\n\n// after: clean cache\n// $ go clean -cache && go build ./...","handlingStrategy":"try-catch","validationCode":"// No pre-check can predict timestamp field corruption.\n// Same hardware reliability and cache hygiene practices apply.","typeGuard":"func isNegativeTimestamp(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"negative timestamp\")\n}","tryCatchPattern":"// entry, err := cache.Get(id)\n// if err != nil {\n//     // Negative timestamp — corrupt timestamp field. Rebuild.\n//     output = rebuild()\n// }","preventionTips":["Run go clean -cache after Go version changes","Ensure reliable hardware (RAM, disk) to prevent bit-level corruption","Keep cache on local reliable storage","Avoid shared/network cache directories that may introduce corruption"],"tags":["go","build-cache","corruption","disk-cache"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}