{"record":{"id":"2a42cbf2b9ac029c","repo":"golang/go","slug":"please-use-outfilelist-flag-instead-of-o","errorCode":null,"errorMessage":"please use '-outfilelist' flag instead of '-o'","messagePattern":"please use '-outfilelist' flag instead of '-o'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/cover/cover.go","lineNumber":176,"sourceCode":"\t\tcase \"atomic\":\n\t\t\tcounterStmt = atomicCounterStmt\n\t\t\tcmode = coverage.CtrModeAtomic\n\t\tcase \"regonly\":\n\t\t\tcounterStmt = nil\n\t\t\tcmode = coverage.CtrModeRegOnly\n\t\tcase \"testmain\":\n\t\t\tcounterStmt = nil\n\t\t\tcmode = coverage.CtrModeTestMain\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"unknown -mode %v\", *mode)\n\t\t}\n\n\t\tif flag.NArg() == 0 {\n\t\t\treturn fmt.Errorf(\"missing source file(s)\")\n\t\t} else {\n\t\t\tif *pkgcfg != \"\" {\n\t\t\t\tif *output != \"\" {\n\t\t\t\t\treturn fmt.Errorf(\"please use '-outfilelist' flag instead of '-o'\")\n\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 != \"\" {","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/cover/cover.go#L158-L194","documentation":"Thrown by 'go tool cover' parseFlags in package-config mode (-pkgcfg set) when -o is also set. In -pkgcfg mode the tool writes multiple instrumented outputs whose paths come from -outfilelist, so a single -o output is meaningless and explicitly disallowed to prevent silent data loss.","triggerScenarios":"`go tool cover -mode=set -pkgcfg=p.cfg -outfilelist=files.txt -o=out.go input.go`.","commonSituations":"Adapting a single-file cover invocation to the package workflow and forgetting to remove -o. Build-system wrappers that always pass -o.","solutions":["Remove -o when using -pkgcfg; specify all outputs via -outfilelist","Ensure your build harness passes -outfilelist (one path per input file) instead of -o"],"exampleFix":"# before\ngo tool cover -mode=set -pkgcfg=p.cfg -o=out.go -outfilelist=files.txt input.go\n# after\ngo tool cover -mode=set -pkgcfg=p.cfg -outfilelist=files.txt input.go","handlingStrategy":"validation","validationCode":"# When -pkgcfg is set, forbid -o\nif [ -n \"$PKGCFG\" ] && [ -n \"$OUTPUT\" ]; then\n  echo \"do not pass -o with -pkgcfg; use -outfilelist\" >&2; exit 2\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In -pkgcfg mode, always use -outfilelist for outputs","Let `go build -cover` construct the invocation rather than hand-rolling it"],"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-12T13:17:24.610Z"}