golang/go · error
%s: %v
Error message
%s: %v
What it means
Thrown by the Go compiler's gcimporter when opening an export-data file (object/archive) fails. A deferred closure prepends the file name to whatever I/O error os.Open returned, so the message reads as "<filename>: <underlying error>". It is purely an annotation wrapper; the real cause is whatever os.Open reported (missing file, permission denied, not an archive).
Source
Thrown at src/cmd/compile/internal/importer/gcimporter.go:68
return types2.Unsafe, nil
}
return nil, err
}
// no need to re-import if the package was imported completely before
if pkg = packages[id]; pkg != nil && pkg.Complete() {
return
}
// open file
f, err := os.Open(filename)
if err != nil {
return nil, err
}
defer func() {
if err != nil {
// add file name to error
err = fmt.Errorf("%s: %v", filename, err)
}
}()
rc = f
}
defer rc.Close()
buf := bufio.NewReader(rc)
data, err := exportdata.ReadUnified(buf)
if err != nil {
err = fmt.Errorf("import %q: %v", path, err)
return
}
s := string(data)
input := pkgbits.NewPkgDecoder(id, s)
pkg = ReadPackage(nil, packages, input)
returnView on GitHub (pinned to b6b368adc5)
Solutions
- Run go clean -cache then rebuild to regenerate all object/export-data files.
- Verify the path in the error message exists and is readable (ls -l <filename>).
- Reinstall or rebuild the offending dependency with go install <pkg>@latest or go build ./... from a clean tree.
- Check that GOROOT/GOTOOLCHAIN match the go version in use (go env GOROOT GOTOOLCHAIN).
Defensive patterns
Strategy: validation
Validate before calling
// Before invoking the importer, ensure the resolved object file exists and is readable.
import "os"
if info, err := os.Stat(filename); err != nil || info.IsDir() {
return fmt.Errorf("export data unavailable: %s", filename)
} Prevention
- Treat the build cache as ephemeral: go clean -cache whenever you switch toolchains.
- Pin GOFLAGS/GOTOOLCHAIN in CI to avoid surprising path resolutions.
- Validate -importcfg inputs reference existing files before launching the compiler.
When it happens
Trigger: The compiler (or go/types importer) tries to read an object file's export data via gcimporter and os.Open(filename) returns a non-nil error; the deferred wrapper at gcimporter.go:68 then formats it. Triggers when the resolved filename does not exist, is unreadable, or points to a directory.
Common situations: Stale or partially-cleaned build cache (go clean -cache mid-build), corrupted GOROOT/GOPATH, switching Go toolchain versions without rebuilding dependencies, missing vendored object file, or a broken GOFLAGS/-importcfg pointing at a removed file.
Related errors
- import %q: %v
- %s: failed to read .go_export section: %v
- error opening target for caching: %w
- error adding target to cache: %w
- writing metafiles file: %v
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/02e9fc1e8fe3598e.
Report an issue: GitHub.