{"record":{"id":"a53413d7d0d31624","repo":"golang/go","slug":"can-t-decode-input-s-v","errorCode":null,"errorMessage":"can't decode input %s: %v","messagePattern":"can't decode input (.+?): (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/export/main.go","lineNumber":122,"sourceCode":"\tf, err := os.Create(cfg.Output)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif err := gcexportdata.Write(f, fset, pkg); err != nil {\n\t\tf.Close() // ignore error\n\t\treturn err\n\t}\n\treturn f.Close()\n}\n\nfunc readConfig(filename string) (*config, error) {\n\tdata, err := os.ReadFile(filename)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tcfg := new(config)\n\tif err := json.Unmarshal(data, cfg); err != nil {\n\t\treturn nil, fmt.Errorf(\"can't decode input %s: %v\", filename, err)\n\t}\n\tif len(cfg.GoFiles) == 0 {\n\t\treturn nil, fmt.Errorf(\"no files in package %s\", cfg.ImportPath)\n\t}\n\treturn cfg, nil\n}\n\nfunc makeTypesImporter(cfg *config, fset *token.FileSet) types.Importer {\n\timports := make(map[string]*types.Package)\n\timports[\"unsafe\"] = types.Unsafe\n\treturn importerFunc(func(importPath string) (*types.Package, error) {\n\t\tpkgPath, ok := cfg.ImportMap[importPath]\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"can't resolve import %s\", importPath)\n\t\t}\n\t\t// Check for cache hit.\n\t\tif pkg, ok := imports[pkgPath]; ok && pkg.Complete() {\n\t\t\treturn pkg, nil","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/export/main.go#L104-L140","documentation":"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`.","triggerScenarios":"`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.","commonSituations":"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.","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`"],"exampleFix":"# before (hand-edited / truncated cfg)\ngo tool export broken.cfg\n# after (regenerate)\ngo list -export -json ./...  # produces valid .cfg\ngo build ./...","handlingStrategy":"validation","validationCode":"# Validate the .cfg before relying on export\npython3 -c \"import json; c=json.load(open('unit.cfg')); assert c.get('GoFiles'), 'GoFiles missing'\" || echo \"bad cfg\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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`"],"tags":["go-toolchain","export","json","config","go-list","schema"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:17:08.281Z"}