{"record":{"id":"eafbdd2a7d059291","repo":"golang/go","slug":"decoding-go-list-json-v","errorCode":null,"errorMessage":"decoding go list json: %v","messagePattern":"decoding go list json: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/cover/func.go","lineNumber":218,"sourceCode":"\t// Note: usually run as \"go tool cover\" in which case $GOROOT is set,\n\t// in which case runtime.GOROOT() does exactly what we want.\n\tgoTool := filepath.Join(runtime.GOROOT(), \"bin/go\")\n\tcmd := exec.Command(goTool, append([]string{\"list\", \"-e\", \"-json\"}, list...)...)\n\tvar stderr bytes.Buffer\n\tcmd.Stderr = &stderr\n\tstdout, err := cmd.Output()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"cannot run go list: %v\\n%s\", err, stderr.Bytes())\n\t}\n\tdec := json.NewDecoder(bytes.NewReader(stdout))\n\tfor {\n\t\tvar pkg Pkg\n\t\terr := dec.Decode(&pkg)\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"decoding go list json: %v\", err)\n\t\t}\n\t\tpkgs[pkg.ImportPath] = &pkg\n\t}\n\treturn pkgs, nil\n}\n\n// findFile finds the location of the named file in GOROOT, GOPATH etc.\nfunc findFile(pkgs map[string]*Pkg, file string) (string, error) {\n\tif strings.HasPrefix(file, \".\") || filepath.IsAbs(file) {\n\t\t// Relative or absolute path.\n\t\treturn file, nil\n\t}\n\tpkg := pkgs[path.Dir(file)]\n\tif pkg != nil {\n\t\tif pkg.Dir != \"\" {\n\t\t\treturn filepath.Join(pkg.Dir, path.Base(file)), nil\n\t\t}\n\t\tif pkg.Error != nil {","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/cover/func.go#L200-L236","documentation":"Thrown by 'go tool cover' (func.go) when `go list -e -json` succeeds (exit 0) but its stdout cannot be JSON-decoded into the Pkg struct. Because `go list -json` streams one JSON object per package, a decode failure mid-stream indicates truncated or malformed JSON output despite a successful exit.","triggerScenarios":"`go list` exits 0 but emits invalid/incomplete JSON (e.g. output truncated by an OS pipe buffer limit, OOM kill mid-output, or a go-list internal bug). Reachable during -func/-html report generation.","commonSituations":"Very large module sets overflowing pipe buffers. A killed/spiked process truncating output. A buggy or in-development Go toolchain emitting non-conformant JSON. Disk/memory pressure during the listing.","solutions":["Re-run the report; transient truncation often clears","Run `go list -e -json <pkgs> > out.json` manually and validate with a JSON parser to confirm reproducibility","Reduce the package set (narrow the profile's packages) to avoid pipe-buffer truncation","Upgrade the Go toolchain if `go list` JSON output is genuinely malformed"],"exampleFix":"# reproduce & validate\ngo list -e -json ./... > /tmp/list.json\npython3 -c \"import json,sys;[json.loads(l) for l in open('/tmp/list.json')]\" 2>&1 || echo malformed","handlingStrategy":"retry","validationCode":"# Validate go list output is decodable JSON before reporting\nGOFLAGS= go list -e -json ./... > /tmp/list.json\npython3 -c \"import json; [json.loads(l) for l in open('/tmp/list.json')]\" || echo \"non-reproducible truncation; retry\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Retry once on transient pipe truncation","Narrow the package set if the listing is huge"],"tags":["go-toolchain","cover","json","subprocess","go-list"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}