golang/go · error
can't read %q: %v
Error message
can't read %q: %v
What it means
Thrown by 'go tool cover' html.go when os.ReadFile fails on the source file located for a coverage profile entry during HTML report generation. The wrapped error names the profile's FileName and the underlying read error. findFile has already resolved the path, so failure means the resolved file is missing or unreadable.
Source
Thrown at src/cmd/cover/html.go:48
var d templateData
dirs, err := findPkgs(profiles)
if err != nil {
return err
}
for _, profile := range profiles {
fn := profile.FileName
if profile.Mode == "set" {
d.Set = true
}
file, err := findFile(dirs, fn)
if err != nil {
return err
}
src, err := os.ReadFile(file)
if err != nil {
return fmt.Errorf("can't read %q: %v", fn, err)
}
var buf strings.Builder
err = htmlGen(&buf, src, profile.Boundaries(src))
if err != nil {
return err
}
d.Files = append(d.Files, &templateFile{
Name: fn,
Body: template.HTML(buf.String()),
Coverage: percentCovered(profile),
})
}
var out *os.File
if outfile == "" {
var dir string
dir, err = os.MkdirTemp("", "cover")
if err != nil {View on GitHub (pinned to b6b368adc5)
Solutions
- Regenerate the profile in the current source tree before producing the HTML report
- Run `go tool cover -html` from the same module root as the test
- Check read permissions on the source tree
Example fix
# before go tool cover -html=stale.out # after go test -coverprofile=c.out ./... go tool cover -html=c.out -o coverage.html
Defensive patterns
Strategy: validation
Validate before calling
# Confirm every profile file is readable before -html
for f in $(awk '{print $1}' c.out | cut -d: -f1); do
[ -r "$f" ] || echo "missing/unreadable: $f"
done Prevention
- Generate the HTML report immediately after the test run
- Keep the source tree intact between test and report
When it happens
Trigger: `go tool cover -html=profile.out` where a referenced source file no longer exists at the resolved location (findFile returned a path but ReadFile failed).
Common situations: Source files deleted/moved after the profile was generated. Running -html in a different checkout. Permission-denied on source files. Generated files (`.cover.go`) cleaned up. Stale profile.
Related errors
- error reading -outfilelist file %q: %v
- error reading pkgconfig file %q: %v
- did not find package for %s in go list output
- 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/087c339faedd08a6.
Report an issue: GitHub.