golang/go · error

truncated archive

Error message

truncated archive

What it means

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.

Source

Thrown at src/cmd/internal/archive/archive.go:105

	TextHeader []byte
	Arch       string
	Data
}

const (
	entryHeader = "%s%-12d%-6d%-6d%-8o%-10d`\n"
	// In entryHeader the first entry, the name, is always printed as 16 bytes right-padded.
	entryLen   = 16 + 12 + 6 + 6 + 8 + 10 + 1 + 1
	timeFormat = "Jan _2 15:04 2006"
)

var (
	archiveHeader = []byte("!<arch>\n")
	archiveMagic  = []byte("`\n")
	goobjHeader   = []byte("go objec") // truncated to size of archiveHeader

	errCorruptArchive   = errors.New("corrupt archive")
	errTruncatedArchive = errors.New("truncated archive")
	errCorruptObject    = errors.New("corrupt object file")
	errNotObject        = errors.New("unrecognized object file format")
)

type ErrGoObjOtherVersion struct{ magic []byte }

func (e ErrGoObjOtherVersion) Error() string {
	return fmt.Sprintf("go object of a different version: %q", e.magic)
}

// An objReader is an object file reader.
type objReader struct {
	a      *Archive
	b      *bio.Reader
	err    error
	offset int64
	limit  int64
	tmp    [256]byte

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Clean the build cache: `go clean -cache` and rebuild.
  2. Check available disk space on the volume holding GOCACHE / GOPATH (`df -h`).
  3. If the archive is a committed artifact (e.g. in vendor/), regenerate it from source.
  4. Ensure no other process is writing to GOCACHE concurrently; do not share a cache directory across go versions.

Example fix

# before
$ go build ./...
# -> truncated archive
$ df -h .
Filesystem  Size  Used Avail Use%
/dev/x      10G   10G     0 100%

# after
$ go clean -cache && go build ./...
Defensive patterns

Strategy: retry

Validate before calling

func archiveNotTruncated(path string) error {
    info, _ := os.Stat(path)
    if info.Size() < 68 { // "!<arch>\n" + one minimal entry header
        return errors.New("archive file is too small / likely truncated")
    }
    return nil
}

Try / catch

if err != nil && strings.Contains(err.Error(), "truncated archive") {
    go clean -cache  // then retry the build
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/9c9e559fd92bcc6c. Report an issue: GitHub.