golang/go · error
error reading -outfilelist file
Error message
error reading -outfilelist file %q: %v
What it means
Thrown by 'go tool cover' readOutFileList when os.ReadFile fails on the path given to -outfilelist. The wrapped error includes the path and the underlying OS error (e.g. file not found, permission denied). The file is expected to contain one output path per line.
Solutions
- Verify the -outfilelist path exists and is readable before invoking cover
- Use an absolute path to avoid working-directory issues
- Check file permissions if running under a restricted user/CI
Example fix
# before (path wrong / missing) go tool cover -mode=set -pkgcfg=p.cfg -outfilelist=out.txt input.go # after go tool cover -mode=set -pkgcfg=p.cfg -outfilelist=/abs/path/out.txt input.go
Defensive patterns
Strategy: validation
Validate before calling
# Validate outfilelist is readable before calling cover if [ ! -r "$OUTFILELIST" ]; then echo "cannot read -outfilelist $OUTFILELIST" >&2; exit 2; fi
Try / catch
// Go caller of readOutFileList:
data, err := os.ReadFile(path)
if err != nil { return nil, fmt.Errorf("unreadable outfilelist %q: %w", path, err) } Prevention
- Use absolute paths for -outfilelist
- Create the file in the same build step that invokes cover
When it happens
Trigger: `go tool cover -mode=set -pkgcfg=p.cfg -outfilelist=/nonexistent/files.txt input.go`, or pointing -outfilelist at an unreadable/permission-denied file.
Common situations: Wrong working directory producing a relative path that doesn't resolve. Stale path from a previous build. Permissions issue in CI sandboxes. Typo in the path.
Related errors
- error reading pkgconfig file
- can't read
- number of output files
- '-outfilelist' flag applicable only when -pkgcfg used
- please use '-outfilelist' flag instead of '-o'
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/efb628f9134403ea.
Report an issue: GitHub.
Appendix: source
Thrown at src/cmd/cover/cover.go:211
} else {
if *outfilelist != "" {
return fmt.Errorf("'-outfilelist' flag applicable only when -pkgcfg used")
}
}
if flag.NArg() == 1 {
return nil
}
}
} else if flag.NArg() == 0 {
return nil
}
return fmt.Errorf("too many arguments")
}
func readOutFileList(path string) ([]string, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("error reading -outfilelist file %q: %v", path, err)
}
return strings.Split(strings.TrimSpace(string(data)), "\n"), nil
}
func readPackageConfig(path string) error {
data, err := os.ReadFile(path)
if err != nil {
return fmt.Errorf("error reading pkgconfig file %q: %v", path, err)
}
if err := json.Unmarshal(data, &pkgconfig); err != nil {
return fmt.Errorf("error reading pkgconfig file %q: %v", path, err)
}
switch pkgconfig.Granularity {
case "perblock":
cgran = coverage.CtrGranularityPerBlock
case "perfunc":
cgran = coverage.CtrGranularityPerFunc
default:View on GitHub (pinned to b6b368adc5)