golang/go · error
too many arguments
Error message
too many arguments
What it means
Thrown by 'go tool cover' parseFlags as a catch-all when, in source-instrumentation mode (-mode set), more than one input file is given WITHOUT -pkgcfg. Without -pkgcfg the tool only supports a single source file; multiple files require the -pkgcfg package workflow.
Source
Thrown at src/cmd/cover/cover.go:205
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")
}
func readOutFileList(path string) ([]string, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("error reading -outfilelist file %q: %v", path, err)
}
return strings.Split(strings.TrimSpace(string(data)), "\n"), nil
}
func readPackageConfig(path string) error {
data, err := os.ReadFile(path)
if err != nil {
return fmt.Errorf("error reading pkgconfig file %q: %v", path, err)
}
if err := json.Unmarshal(data, &pkgconfig); err != nil {
return fmt.Errorf("error reading pkgconfig file %q: %v", path, err)
}View on GitHub (pinned to b6b368adc5)
Solutions
- Pass exactly one .go file when not using -pkgcfg
- For multi-file packages, use the -pkgcfg + -outfilelist workflow (normally driven by `go build -cover`)
Example fix
# before go tool cover -mode=set a.go b.go # after (single file) go tool cover -mode=set a.go # or use the package workflow via the go command: go build -cover ./...
Defensive patterns
Strategy: validation
Validate before calling
# Without -pkgcfg, allow exactly one input if [ -z "$PKGCFG" ] && [ "$#" -ne 1 ]; then echo "single-file mode needs exactly one input; use -pkgcfg for packages" >&2; exit 2 fi
Prevention
- Use `go build -cover` for whole-package instrumentation
- Reserve direct `go tool cover` single-file use for ad-hoc checks
When it happens
Trigger: `go tool cover -mode=set a.go b.go` (two files, no -pkgcfg).
Common situations: Trying to instrument a whole package directly with `go tool cover` instead of through the go command. Passing a glob that expands to multiple files.
Related errors
- too many options
- -var: %q is not a valid identifier
- unknown -mode %v
- missing source file(s)
- please use '-outfilelist' flag instead of '-o'
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/c10238bf84f67514.
Report an issue: GitHub.