{"record":{"id":"e2a7abfd79af6f07","repo":"golang/go","slug":"number-of-output-files-d-not-equal-to-number-of","errorCode":null,"errorMessage":"number of output files (%d) not equal to number of input files (%d)","messagePattern":"number of output files \\((.+?)\\) not equal to number of input files \\((.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/cover/cover.go","lineNumber":187,"sourceCode":"\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 != \"\" {\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\")","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/cover/cover.go#L169-L205","documentation":"Thrown by 'go tool cover' parseFlags in -pkgcfg mode when the count of output file paths read from -outfilelist does not equal the count of input .go files (flag.Args()). The tool pairs inputs to outputs one-to-one to write instrumented copies, so a mismatch would misroute outputs. The first outfilelist entry is reserved for the cover-vars file, so the remaining count is compared.","triggerScenarios":"Passing 3 input files but an outfilelist with 3 entries (only 2 outputs after the reserved cover-vars entry), or any N-inputs vs (M-1)-outputs mismatch.","commonSituations":"Forgetting that the first outfilelist line is the cover-vars file, not an instrumented output. Generating the outfilelist with a script that drops or duplicates a line. Editing the input list without regenerating outfilelist.","solutions":["Regenerate -outfilelist so it has exactly (number of input files + 1) lines: the cover-vars file first, then one output per input","Let the go command drive -pkgcfg/-outfilelist so the lists stay in sync","Add a build-step assertion that len(outputfiles)-1 == len(inputs) before invoking cover"],"exampleFix":"# inputs: a.go b.go c.go (3)\n# before (outfilelist has 3 lines)\ngo tool cover -mode=set -pkgcfg=p.cfg -outfilelist=list.txt a.go b.go c.go\n# after (outfilelist has 4 lines: covervars.go + 3 outputs)\ncovvars.go\\na.cover.go\\nb.cover.go\\nc.cover.go","handlingStrategy":"validation","validationCode":"# Verify outfilelist length == inputs + 1 (cover-vars file first)\nmapfile -t outs < \"$OUTFILELIST\"\ninputs=( \"$@\" )\nif [ $(( ${#outs[@]} - 1 )) -ne ${#inputs[@]} ]; then\n  echo \"outfilelist must have inputs+1 lines\" >&2; exit 2\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Regenerate outfilelist whenever the input file set changes","Remember the first outfilelist entry is the cover-vars file, not an output"],"tags":["go-toolchain","cover","cli-flags","pkgcfg","count-mismatch"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}