golang/go · error

too many options

Error message

too many options

What it means

Thrown by 'go tool cover' parseFlags when both -html and -func flags are set to non-empty values. The tool only allows one output mode at a time (HTML coverage report OR per-function coverage percentages). Setting both is treated as conflicting/ambiguous input.

Source

Thrown at src/cmd/cover/cover.go:136

	// Output HTML or function coverage information.
	if *htmlOut != "" {
		err = htmlOutput(profile, *output)
	} else {
		err = funcOutput(profile, *output)
	}

	if err != nil {
		fmt.Fprintf(os.Stderr, "cover: %v\n", err)
		os.Exit(2)
	}
}

// parseFlags sets the profile and counterStmt globals and performs validations.
func parseFlags() error {
	profile = *htmlOut
	if *funcOut != "" {
		if profile != "" {
			return fmt.Errorf("too many options")
		}
		profile = *funcOut
	}

	// Must either display a profile or rewrite Go source.
	if (profile == "") == (*mode == "") {
		return fmt.Errorf("too many options")
	}

	if *varVar != "" && !token.IsIdentifier(*varVar) {
		return fmt.Errorf("-var: %q is not a valid identifier", *varVar)
	}

	if *mode != "" {
		switch *mode {
		case "set":
			counterStmt = setCounterStmt
			cmode = coverage.CtrModeSet

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Choose exactly one of -html or -func per invocation
  2. Run two separate `go tool cover` commands if you need both outputs
  3. Wrap the invocation so the two flags are mutually exclusive (e.g. shell case/if)

Example fix

# before
go tool cover -html=c.out -func=c.out
# after
go tool cover -html=c.out -o coverage.html
go tool cover -func=c.out
Defensive patterns

Strategy: validation

Validate before calling

# Shell: enforce mutual exclusion before invoking cover
if [ -n "$HTML" ] && [ -n "$FUNC" ]; then
  echo "use only one of -html or -func" >&2; exit 2
fi

Prevention

When it happens

Trigger: Invoking `go tool cover -html=profile.out -func=profile.out` (or any invocation where both -html and -func are non-empty). The first branch: profile is set from htmlOut, and if funcOut is also set the error fires.

Common situations: User typo combining flags meant to be alternatives. Copy-pasting a command that had one mode and appending another. Scripts that template flags conditionally without mutual exclusion.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/4ff20f0d725414cd. Report an issue: GitHub.