{"record":{"id":"7d3b1a029d7a32da","repo":"golang/go","slug":"did-not-find-package-for-s-in-go-list-output","errorCode":null,"errorMessage":"did not find package for %s in go list output","messagePattern":"did not find package for (.+?) in go list output","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/cover/func.go","lineNumber":240,"sourceCode":"\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 {\n\t\t\treturn \"\", errors.New(pkg.Error.Err)\n\t\t}\n\t}\n\treturn \"\", fmt.Errorf(\"did not find package for %s in go list output\", file)\n}\n\nfunc percent(covered, total int64) float64 {\n\tif total == 0 {\n\t\ttotal = 1 // Avoid zero denominator.\n\t}\n\treturn 100.0 * float64(covered) / float64(total)\n}\n","sourceCodeStart":222,"sourceCodeEnd":249,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/cover/func.go#L222-L249","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","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"],"exampleFix":"# before (stale profile from another checkout)\ngo tool cover -func=old.out\n# after\ngo test -coverprofile=c.out ./...\ngo tool cover -func=c.out","handlingStrategy":"validation","validationCode":"# Confirm every profile file's dir maps to a package before reporting\nfor f in $(awk '{print $1}' c.out | cut -d: -f1); do\n  d=$(dirname \"$f\"); go list -e \"$d\" >/dev/null 2>&1 || echo \"unresolved: $f\"\ndone","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate and consume the profile in the same checkout","Re-run `go test -coverprofile` after any refactor before reporting"],"tags":["go-toolchain","cover","profile","path-resolution","go-list"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}