golang/go · error
internal error: unable to locate build action for package %q
Error message
internal error: unable to locate build action for package %q run action
What it means
BuildActionCoverMetaFile walks the run-action's dependency graph to find the matching 'build' action for the package under test, in order to locate the coverage meta-data file. If no predecessor build action has the same ImportPath, this internal error is returned. It indicates the action graph wasn't constructed as expected for 'go test -cover'.
Source
Thrown at src/cmd/go/internal/work/cover.go:75
if cfg.BuildN {
return metaFile, nil
}
f, err := os.Open(metaFile)
if err != nil {
return "", err
}
defer f.Close()
fi, err2 := f.Stat()
if err2 != nil {
return "", err2
}
if fi.Size() == 0 {
return "", nil
}
return metaFile, nil
}
}
return "", fmt.Errorf("internal error: unable to locate build action for package %q run action", p.ImportPath)
}
// WriteCoveragePercent writes out to the writer 'w' a "percent
// statements covered" for the package whose test-run action is
// 'runAct', based on the meta-data file 'mf'. This helper is used in
// cases where a user runs "go test -cover" on a package that has
// functions but no tests; in the normal case (package has tests)
// the percentage is written by the test binary when it runs.
func WriteCoveragePercent(b *Builder, runAct *Action, mf string, w io.Writer) error {
dir := filepath.Dir(mf)
output, cerr := b.CovData(runAct, "percent", "-i", dir)
if cerr != nil {
return b.Shell(runAct).reportCmd("", "", output, cerr)
}
_, werr := w.Write(output)
return werr
}
View on GitHub (pinned to b6b368adc5)
Solutions
- Update to the latest patch release of Go — this is typically a toolchain bug, not user error.
- Simplify the -coverpkg pattern to see if a specific dependency shape triggers it.
- Run 'go test -cover ./...' instead of narrow patterns to see if the issue is pattern-specific.
- File a Go issue with the package layout and exact go test invocation.
Example fix
// before $ go test -coverpkg=./... -cover ./... // error: internal error: unable to locate build action for package "example.com/m" run action // after — update toolchain and simplify $ go1.23.x test -cover ./... # use latest patch # if persists: report at https://go.dev/issue with reproduction
Defensive patterns
Strategy: fallback
Prevention
- Keep Go up to date — internal action-graph errors are toolchain bugs.
- Simplify -coverpkg patterns if a specific shape triggers it.
- Capture the exact 'go test' invocation and package layout when reporting.
When it happens
Trigger: Invoked during 'go test -cover' (especially with functions but no tests, or with -coverpkg) when the run action's barrier dependency has no build predecessor matching the package's ImportPath. Should be unreachable for well-formed graphs; indicates a regression in action-graph construction.
Common situations: A Go toolchain regression in coverage action wiring; an edge case with empty packages, test-only packages, or unusual -coverpkg combinations; running a patched go command.
Related errors
- marshal MetaFileCollection: %v
- writing metafiles file: %v
- import cycle not allowed in test
- multiple definitions of TestMain
- valid modes are "set", "count", or "atomic"
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/d7809e7f6991598c.
Report an issue: GitHub.