{"record":{"id":"aa16ae6af82f3f08","repo":"golang/go","slug":"error-reading-pkgconfig-file-q-v","errorCode":null,"errorMessage":"error reading pkgconfig file %q: %v","messagePattern":"error reading pkgconfig file %q: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/cover/cover.go","lineNumber":219,"sourceCode":"\t\t}\n\t} else if flag.NArg() == 0 {\n\t\treturn nil\n\t}\n\treturn fmt.Errorf(\"too many arguments\")\n}\n\nfunc readOutFileList(path string) ([]string, error) {\n\tdata, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error reading -outfilelist file %q: %v\", path, err)\n\t}\n\treturn strings.Split(strings.TrimSpace(string(data)), \"\\n\"), nil\n}\n\nfunc readPackageConfig(path string) error {\n\tdata, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error reading pkgconfig file %q: %v\", path, err)\n\t}\n\tif err := json.Unmarshal(data, &pkgconfig); err != nil {\n\t\treturn fmt.Errorf(\"error reading pkgconfig file %q: %v\", path, err)\n\t}\n\tswitch pkgconfig.Granularity {\n\tcase \"perblock\":\n\t\tcgran = coverage.CtrGranularityPerBlock\n\tcase \"perfunc\":\n\t\tcgran = coverage.CtrGranularityPerFunc\n\tdefault:\n\t\treturn fmt.Errorf(`%s: pkgconfig requires perblock/perfunc value`, path)\n\t}\n\treturn nil\n}\n\n// Block represents the information about a basic block to be recorded in the analysis.\n// Note: Our definition of basic block is based on control structures; we don't break\n// apart && and ||. We could but it doesn't seem important enough to bother.","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/cover/cover.go#L201-L237","documentation":"Thrown by 'go tool cover' readPackageConfig when os.ReadFile fails on the -pkgcfg path. The wrapped error includes the path and the underlying OS error. The pkgcfg file is a JSON document (cmd/internal/cov/covcmd.CoverPkgConfig) produced by the go build toolchain describing the package to instrument.","triggerScenarios":"`go tool cover -mode=set -pkgcfg=/missing/pkg.cfg ...` where the file cannot be read.","commonSituations":"The go command usually generates this file; hitting it manually with a wrong path. Relative path resolved from an unexpected CWD. Permissions. Race where the file was cleaned up before cover read it.","solutions":["Confirm the -pkgcfg path exists and is readable","Use an absolute path","Normally let `go build -cover` generate and pass the pkgcfg file rather than hand-crafting it"],"exampleFix":"# before\ngo tool cover -mode=set -pkgcfg=p.cfg -outfilelist=o.txt input.go\n# after (valid absolute path)\ngo tool cover -mode=set -pkgcfg=/abs/path/p.cfg -outfilelist=o.txt input.go","handlingStrategy":"validation","validationCode":"# Validate pkgcfg is readable before calling cover\nif [ ! -r \"$PKGCFG\" ]; then echo \"cannot read -pkgcfg $PKGCFG\" >&2; exit 2; fi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Let `go build -cover` generate the pkgcfg file","Use absolute paths and confirm the file exists in CI logs"],"tags":["go-toolchain","cover","filesystem","pkgcfg","io-error"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}