{"record":{"id":"9c9e559fd92bcc6c","repo":"golang/go","slug":"truncated-archive","errorCode":null,"errorMessage":"truncated archive","messagePattern":"truncated archive","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/archive/archive.go","lineNumber":105,"sourceCode":"\tTextHeader []byte\n\tArch       string\n\tData\n}\n\nconst (\n\tentryHeader = \"%s%-12d%-6d%-6d%-8o%-10d`\\n\"\n\t// In entryHeader the first entry, the name, is always printed as 16 bytes right-padded.\n\tentryLen   = 16 + 12 + 6 + 6 + 8 + 10 + 1 + 1\n\ttimeFormat = \"Jan _2 15:04 2006\"\n)\n\nvar (\n\tarchiveHeader = []byte(\"!<arch>\\n\")\n\tarchiveMagic  = []byte(\"`\\n\")\n\tgoobjHeader   = []byte(\"go objec\") // truncated to size of archiveHeader\n\n\terrCorruptArchive   = errors.New(\"corrupt archive\")\n\terrTruncatedArchive = errors.New(\"truncated archive\")\n\terrCorruptObject    = errors.New(\"corrupt object file\")\n\terrNotObject        = errors.New(\"unrecognized object file format\")\n)\n\ntype ErrGoObjOtherVersion struct{ magic []byte }\n\nfunc (e ErrGoObjOtherVersion) Error() string {\n\treturn fmt.Sprintf(\"go object of a different version: %q\", e.magic)\n}\n\n// An objReader is an object file reader.\ntype objReader struct {\n\ta      *Archive\n\tb      *bio.Reader\n\terr    error\n\toffset int64\n\tlimit  int64\n\ttmp    [256]byte","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/archive/archive.go#L87-L123","documentation":"Defined as errTruncatedArchive in cmd/internal/archive. Distinct from \"corrupt archive\": this sentinel specifically means the archive's structure is internally consistent so far, but the file ended before all the bytes promised by a header were read (an entry declared a size that extends past EOF). The reader distinguishes the two so callers can tell truncation (often I/O or partial-write) from structural corruption.","triggerScenarios":"An ar entry header lists N bytes of content but the file ends after fewer than N. Reading an archive that was being written concurrently. A file copied incompletely (scp/rsync interrupted). A build-cache entry whose write was cut short by ENOSPC.","commonSituations":"Out-of-disk-space during a build. A crash or kill during compilation leaving half-written .a files in the cache. Network filesystems serving truncated objects. Concurrent `go build` invocations racing on the same cache key with an old buggy go version.","solutions":["Clean the build cache: `go clean -cache` and rebuild.","Check available disk space on the volume holding GOCACHE / GOPATH (`df -h`).","If the archive is a committed artifact (e.g. in vendor/), regenerate it from source.","Ensure no other process is writing to GOCACHE concurrently; do not share a cache directory across go versions."],"exampleFix":"# before\n$ go build ./...\n# -> truncated archive\n$ df -h .\nFilesystem  Size  Used Avail Use%\n/dev/x      10G   10G     0 100%\n\n# after\n$ go clean -cache && go build ./...","handlingStrategy":"retry","validationCode":"func archiveNotTruncated(path string) error {\n    info, _ := os.Stat(path)\n    if info.Size() < 68 { // \"!<arch>\\n\" + one minimal entry header\n        return errors.New(\"archive file is too small / likely truncated\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"truncated archive\") {\n    go clean -cache  // then retry the build\n}","preventionTips":["Monitor free disk space on the GOCACHE volume during builds.","Do not kill builds mid-write; use `go build` signal handling cleanly.","Validate downloaded/cached artifacts with a checksum before use."],"tags":["go-toolchain","archive","linker","truncation","build-cache"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}