golang/go · error
can't decode input %s: %v
Error message
can't decode input %s: %v
What it means
Thrown by `go tool export` (src/cmd/export/main.go) readConfig when the .cfg config file (produced by `go list -export`) is read successfully but cannot be JSON-unmarshalled into the config struct (ImportPath, Compiler, GoVersion, GoFiles, ImportMap, PackageFile, Output). The error wraps the filename and the json error. The export tool is internal, driven only by `go list -export`.
Source
Thrown at src/cmd/export/main.go:122
f, err := os.Create(cfg.Output)
if err != nil {
return err
}
if err := gcexportdata.Write(f, fset, pkg); err != nil {
f.Close() // ignore error
return err
}
return f.Close()
}
func readConfig(filename string) (*config, error) {
data, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
cfg := new(config)
if err := json.Unmarshal(data, cfg); err != nil {
return nil, fmt.Errorf("can't decode input %s: %v", filename, err)
}
if len(cfg.GoFiles) == 0 {
return nil, fmt.Errorf("no files in package %s", cfg.ImportPath)
}
return cfg, nil
}
func makeTypesImporter(cfg *config, fset *token.FileSet) types.Importer {
imports := make(map[string]*types.Package)
imports["unsafe"] = types.Unsafe
return importerFunc(func(importPath string) (*types.Package, error) {
pkgPath, ok := cfg.ImportMap[importPath]
if !ok {
return nil, fmt.Errorf("can't resolve import %s", importPath)
}
// Check for cache hit.
if pkg, ok := imports[pkgPath]; ok && pkg.Complete() {
return pkg, nilView on GitHub (pinned to b6b368adc5)
Solutions
- Regenerate the .cfg via `go list -export` rather than editing it
- Validate the .cfg parses as JSON and has the expected top-level fields (GoFiles array, ImportMap map, etc.)
- Ensure the go and export binaries are from the same GOROOT/release
- Do not invoke `go tool export` directly — it is undocumented and exists for `go list -export`
Example fix
# before (hand-edited / truncated cfg) go tool export broken.cfg # after (regenerate) go list -export -json ./... # produces valid .cfg go build ./...
Defensive patterns
Strategy: validation
Validate before calling
# Validate the .cfg before relying on export
python3 -c "import json; c=json.load(open('unit.cfg')); assert c.get('GoFiles'), 'GoFiles missing'" || echo "bad cfg" Prevention
- Never hand-write unit.cfg; let `go list -export` produce it
- Keep go and go-tool-export from the same GOROOT
- Avoid calling `go tool export` directly — it is for `go list -export`
When it happens
Trigger: `go list -export` (or a direct `go tool export unit.cfg`) where unit.cfg contains invalid JSON or fields whose types do not match the config struct. Reachable only via the export toolchain subcommand.
Common situations: Truncated .cfg from a killed build. Version skew between go and go-tool-export. A hand-crafted or edited .cfg. Disk write corruption. Mixing gccgo/gc config formats.
Related errors
- no files in package %s
- decoding go list json: %v
- can't resolve import %s
- can't resolve export %s
- cannot run go list: %v %s
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/a53413d7d0d31624.
Report an issue: GitHub.