golang/go · error

loading compiled Go files from cache: %w

Error message

loading compiled Go files from cache: %w

What it means

When a package action needs compiled Go files (needCompiledGoFiles flag set, used for export data / inlining) and the build cache should have them, b.loadCachedCompiledGoFiles is called to retrieve them. If that returns an error — cache miss after a hit was promised, corrupt cache entry, or a stale .a — it's wrapped with this message and returned, failing the build.

Source

Thrown at src/cmd/go/internal/work/exec.go:780

	var srcfiles []string // .go and non-.go
	srcfiles = append(srcfiles, gofiles...)
	srcfiles = append(srcfiles, sfiles...)
	srcfiles = append(srcfiles, cfiles...)
	b.cacheSrcFiles(a, srcfiles)

	// Sanity check only, since Package.load already checked as well.
	if len(gofiles) == 0 {
		return &load.NoGoError{Package: p}
	}

	// Prepare Go vet config if needed.
	if need&needVet != 0 {
		buildVetConfig(a, srcfiles, a.Deps)
		need &^= needVet
	}
	if need&needCompiledGoFiles != 0 {
		if err := b.loadCachedCompiledGoFiles(a); err != nil {
			return fmt.Errorf("loading compiled Go files from cache: %w", err)
		}
		need &^= needCompiledGoFiles
	}
	if need == 0 {
		// Nothing left to do.
		return nil
	}

	// Collect symbol ABI requirements from assembly.
	symabis, err := BuildToolchain.symabis(b, a, sfiles)
	if err != nil {
		return err
	}

	// Prepare Go import config.
	// We start it off with a comment so it can't be empty, so icfg.Bytes() below is never nil.
	// It should never be empty anyway, but there have been bugs in the past that resulted
	// in empty configs, which then unfortunately turn into "no config passed to compiler",

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Run 'go clean -cache' to invalidate the corrupt entry.
  2. Ensure GOCACHE is local (not NFS/network) and on a writable volume with free space.
  3. Use one GOCACHE per Go version to avoid cross-version cache corruption.
  4. Re-run the build — a fresh compile repopulates the cache.

Example fix

// before
$ go build ./...
// error: loading compiled Go files from cache: ... corrupt export data

// after
$ go clean -cache
$ export GOCACHE=$HOME/.cache/go-build
$ go build ./...
Defensive patterns

Strategy: fallback

Try / catch

// On cache-load failures, reset the cache and rebuild.
if err := build(); err != nil && strings.Contains(err.Error(), "loading compiled Go files from cache") {
    goCleanCache()
    err = build()
}

Prevention

When it happens

Trigger: Building a package whose compiled export is expected from cache but the cache entry is missing/corrupt. Happens after 'go clean -cache' partial runs, concurrent cache eviction, or a cache shared across incompatible toolchains.

Common situations: GOCACHE corrupted by a crash mid-write; mixing GOCACHE across Go versions; cache on a network filesystem with consistency issues; disk full when the .a was written.

Related errors


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