golang/go · error
decoding go list json: %v
Error message
decoding go list json: %v
What it means
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.
Source
Thrown at src/cmd/cover/func.go:218
// Note: usually run as "go tool cover" in which case $GOROOT is set,
// in which case runtime.GOROOT() does exactly what we want.
goTool := filepath.Join(runtime.GOROOT(), "bin/go")
cmd := exec.Command(goTool, append([]string{"list", "-e", "-json"}, list...)...)
var stderr bytes.Buffer
cmd.Stderr = &stderr
stdout, err := cmd.Output()
if err != nil {
return nil, fmt.Errorf("cannot run go list: %v\n%s", err, stderr.Bytes())
}
dec := json.NewDecoder(bytes.NewReader(stdout))
for {
var pkg Pkg
err := dec.Decode(&pkg)
if err == io.EOF {
break
}
if err != nil {
return nil, fmt.Errorf("decoding go list json: %v", err)
}
pkgs[pkg.ImportPath] = &pkg
}
return pkgs, nil
}
// findFile finds the location of the named file in GOROOT, GOPATH etc.
func findFile(pkgs map[string]*Pkg, file string) (string, error) {
if strings.HasPrefix(file, ".") || filepath.IsAbs(file) {
// Relative or absolute path.
return file, nil
}
pkg := pkgs[path.Dir(file)]
if pkg != nil {
if pkg.Dir != "" {
return filepath.Join(pkg.Dir, path.Base(file)), nil
}
if pkg.Error != nil {View on GitHub (pinned to b6b368adc5)
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
Example fix
# reproduce & validate
go list -e -json ./... > /tmp/list.json
python3 -c "import json,sys;[json.loads(l) for l in open('/tmp/list.json')]" 2>&1 || echo malformed Defensive patterns
Strategy: retry
Validate before calling
# Validate go list output is decodable JSON before reporting
GOFLAGS= go list -e -json ./... > /tmp/list.json
python3 -c "import json; [json.loads(l) for l in open('/tmp/list.json')]" || echo "non-reproducible truncation; retry" Prevention
- Retry once on transient pipe truncation
- Narrow the package set if the listing is huge
When it happens
Trigger: `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.
Common situations: 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.
Related errors
- cannot run go list: %v %s
- did not find package for %s in go list output
- can't decode input %s: %v
- ${cmdline[0]}: ${err}
- too many options
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/eafbdd2a7d059291.
Report an issue: GitHub.