golang/go · error
number of output files (%d) not equal to number of input fil
Error message
number of output files (%d) not equal to number of input files (%d)
What it means
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.
Source
Thrown at src/cmd/cover/cover.go:187
}
if flag.NArg() == 0 {
return fmt.Errorf("missing source file(s)")
} else {
if *pkgcfg != "" {
if *output != "" {
return fmt.Errorf("please use '-outfilelist' flag instead of '-o'")
}
var err error
if outputfiles, err = readOutFileList(*outfilelist); err != nil {
return err
}
covervarsoutfile = outputfiles[0]
outputfiles = outputfiles[1:]
numInputs := len(flag.Args())
numOutputs := len(outputfiles)
if numOutputs != numInputs {
return fmt.Errorf("number of output files (%d) not equal to number of input files (%d)", numOutputs, numInputs)
}
if err := readPackageConfig(*pkgcfg); err != nil {
return err
}
return nil
} 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")View on GitHub (pinned to b6b368adc5)
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
Example fix
# inputs: a.go b.go c.go (3) # before (outfilelist has 3 lines) go tool cover -mode=set -pkgcfg=p.cfg -outfilelist=list.txt a.go b.go c.go # after (outfilelist has 4 lines: covervars.go + 3 outputs) covvars.go\na.cover.go\nb.cover.go\nc.cover.go
Defensive patterns
Strategy: validation
Validate before calling
# Verify outfilelist length == inputs + 1 (cover-vars file first)
mapfile -t outs < "$OUTFILELIST"
inputs=( "$@" )
if [ $(( ${#outs[@]} - 1 )) -ne ${#inputs[@]} ]; then
echo "outfilelist must have inputs+1 lines" >&2; exit 2
fi Prevention
- Regenerate outfilelist whenever the input file set changes
- Remember the first outfilelist entry is the cover-vars file, not an output
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- please use '-outfilelist' flag instead of '-o'
- '-outfilelist' flag applicable only when -pkgcfg used
- too many options
- -var: %q is not a valid identifier
- unknown -mode %v
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/e2a7abfd79af6f07.
Report an issue: GitHub.