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

  1. Re-run the report; transient truncation often clears
  2. Run `go list -e -json <pkgs> > out.json` manually and validate with a JSON parser to confirm reproducibility
  3. Reduce the package set (narrow the profile's packages) to avoid pipe-buffer truncation
  4. 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

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


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/eafbdd2a7d059291. Report an issue: GitHub.