golang/go · error
did not find package for %s in go list output
Error message
did not find package for %s in go list output
What it means
Thrown by 'go tool cover' findFile (func.go) when a source file path from the coverage profile cannot be mapped to a package in the `go list -json` output. findFile looks up pkgs[path.Dir(file)]; if no package owns that directory and there's no pkg.Error, the file is unresolvable.
Source
Thrown at src/cmd/cover/func.go:240
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 {
return "", errors.New(pkg.Error.Err)
}
}
return "", fmt.Errorf("did not find package for %s in go list output", file)
}
func percent(covered, total int64) float64 {
if total == 0 {
total = 1 // Avoid zero denominator.
}
return 100.0 * float64(covered) / float64(total)
}
View on GitHub (pinned to b6b368adc5)
Solutions
- Regenerate the coverage profile in the current checkout (`go test -coverprofile=...`)
- Ensure you run `go tool cover` from the same module root where the test ran
- If the file path is absolute or relative ('.'/'..'), findFile short-circuits — convert external paths accordingly
Example fix
# before (stale profile from another checkout) go tool cover -func=old.out # after go test -coverprofile=c.out ./... go tool cover -func=c.out
Defensive patterns
Strategy: validation
Validate before calling
# Confirm every profile file's dir maps to a package before reporting
for f in $(awk '{print $1}' c.out | cut -d: -f1); do
d=$(dirname "$f"); go list -e "$d" >/dev/null 2>&1 || echo "unresolved: $f"
done Prevention
- Generate and consume the profile in the same checkout
- Re-run `go test -coverprofile` after any refactor before reporting
When it happens
Trigger: `go tool cover -func=profile.out` / `-html` where the profile references a file whose directory is not a package known to `go list` — e.g. a generated file whose directory was removed, a vendored path, or a stale profile from a different checkout.
Common situations: Profile generated in one checkout/module then consumed in another where the package layout differs. Deleted or moved packages. Files under /tmp or non-module paths. Stale profile after a refactor.
Related errors
- cannot run go list: %v %s
- decoding go list json: %v
- can't read %q: %v
- too many options
- -var: %q is not a valid identifier
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/7d3b1a029d7a32da.
Report an issue: GitHub.