{"record":{"id":"d7809e7f6991598c","repo":"golang/go","slug":"internal-error-unable-to-locate-build-action-for","errorCode":null,"errorMessage":"internal error: unable to locate build action for package %q run action","messagePattern":"internal error: unable to locate build action for package %q run action","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/work/cover.go","lineNumber":75,"sourceCode":"\t\t\tif cfg.BuildN {\n\t\t\t\treturn metaFile, nil\n\t\t\t}\n\t\t\tf, err := os.Open(metaFile)\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", err\n\t\t\t}\n\t\t\tdefer f.Close()\n\t\t\tfi, err2 := f.Stat()\n\t\t\tif err2 != nil {\n\t\t\t\treturn \"\", err2\n\t\t\t}\n\t\t\tif fi.Size() == 0 {\n\t\t\t\treturn \"\", nil\n\t\t\t}\n\t\t\treturn metaFile, nil\n\t\t}\n\t}\n\treturn \"\", fmt.Errorf(\"internal error: unable to locate build action for package %q run action\", p.ImportPath)\n}\n\n// WriteCoveragePercent writes out to the writer 'w' a \"percent\n// statements covered\" for the package whose test-run action is\n// 'runAct', based on the meta-data file 'mf'. This helper is used in\n// cases where a user runs \"go test -cover\" on a package that has\n// functions but no tests; in the normal case (package has tests)\n// the percentage is written by the test binary when it runs.\nfunc WriteCoveragePercent(b *Builder, runAct *Action, mf string, w io.Writer) error {\n\tdir := filepath.Dir(mf)\n\toutput, cerr := b.CovData(runAct, \"percent\", \"-i\", dir)\n\tif cerr != nil {\n\t\treturn b.Shell(runAct).reportCmd(\"\", \"\", output, cerr)\n\t}\n\t_, werr := w.Write(output)\n\treturn werr\n}\n","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/work/cover.go#L57-L93","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n$ go test -coverpkg=./... -cover ./...\n// error: internal error: unable to locate build action for package \"example.com/m\" run action\n\n// after — update toolchain and simplify\n$ go1.23.x test -cover ./...   # use latest patch\n# if persists: report at https://go.dev/issue with reproduction","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["coverage","testing","internal","build-graph"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}