{"record":{"id":"85bd2d86eaa52fe3","repo":"golang/go","slug":"outfilelist-flag-applicable-only-when-pkgcfg-u","errorCode":null,"errorMessage":"'-outfilelist' flag applicable only when -pkgcfg used","messagePattern":"'-outfilelist' flag applicable only when -pkgcfg used","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/cover/cover.go","lineNumber":195,"sourceCode":"\t\t\t\t}\n\t\t\t\tvar err error\n\t\t\t\tif outputfiles, err = readOutFileList(*outfilelist); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tcovervarsoutfile = outputfiles[0]\n\t\t\t\toutputfiles = outputfiles[1:]\n\t\t\t\tnumInputs := len(flag.Args())\n\t\t\t\tnumOutputs := len(outputfiles)\n\t\t\t\tif numOutputs != numInputs {\n\t\t\t\t\treturn fmt.Errorf(\"number of output files (%d) not equal to number of input files (%d)\", numOutputs, numInputs)\n\t\t\t\t}\n\t\t\t\tif err := readPackageConfig(*pkgcfg); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\treturn nil\n\t\t\t} else {\n\t\t\t\tif *outfilelist != \"\" {\n\t\t\t\t\treturn fmt.Errorf(\"'-outfilelist' flag applicable only when -pkgcfg used\")\n\t\t\t\t}\n\t\t\t}\n\t\t\tif flag.NArg() == 1 {\n\t\t\t\treturn nil\n\t\t\t}\n\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","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/cover/cover.go#L177-L213","documentation":"Thrown by 'go tool cover' parseFlags when -outfilelist is set but -pkgcfg is NOT set. -outfilelist is only meaningful in the full-package instrumentation workflow (which requires -pkgcfg); using it in single-file mode is a user error.","triggerScenarios":"`go tool cover -mode=set -outfilelist=files.txt input.go` (no -pkgcfg).","commonSituations":"Copy-pasting flags from a package-instrumentation command into a single-file invocation. Stale build script that leaves -outfilelist set after removing -pkgcfg.","solutions":["Remove -outfilelist unless you are also using -pkgcfg","If instrumenting a package, add -pkgcfg pointing at a valid config file"],"exampleFix":"# before\ngo tool cover -mode=set -outfilelist=files.txt input.go\n# after\ngo tool cover -mode=set input.go","handlingStrategy":"validation","validationCode":"# Only allow -outfilelist with -pkgcfg\nif [ -n \"$OUTFILELIST\" ] && [ -z \"$PKGCFG\" ]; then\n  echo \"-outfilelist requires -pkgcfg\" >&2; exit 2\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep -outfilelist and -pkgcfg paired in scripts","Strip both when downgrading to single-file mode"],"tags":["go-toolchain","cover","cli-flags","flag-conflict","pkgcfg"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}