golang/go · error
unknown -mode %v
Error message
unknown -mode %v
What it means
Thrown by 'go tool cover' parseFlags when -mode is set to a value outside the allowed set. Valid modes are set, count, atomic, regonly, and testmain. Each maps to a counter statement strategy and a coverage.CounterMode; anything else falls through the switch's default branch.
Source
Thrown at src/cmd/cover/cover.go:168
if *mode != "" {
switch *mode {
case "set":
counterStmt = setCounterStmt
cmode = coverage.CtrModeSet
case "count":
counterStmt = incCounterStmt
cmode = coverage.CtrModeCount
case "atomic":
counterStmt = atomicCounterStmt
cmode = coverage.CtrModeAtomic
case "regonly":
counterStmt = nil
cmode = coverage.CtrModeRegOnly
case "testmain":
counterStmt = nil
cmode = coverage.CtrModeTestMain
default:
return fmt.Errorf("unknown -mode %v", *mode)
}
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 {View on GitHub (pinned to b6b368adc5)
Solutions
- Use one of: set, count, atomic, regonly, testmain (lowercase)
- Check `go tool cover -help` for the modes supported by your Go version
- Upgrade or downgrade Go if a mode you expect is missing
Example fix
# before go tool cover -mode=total file.go # after go tool cover -mode=count file.go
Defensive patterns
Strategy: validation
Validate before calling
# Validate mode against the allowed enum MODES="set count atomic regonly testmain" if ! echo " $MODES " | grep -q " $MODE "; then echo "unknown -mode $MODE; pick from: $MODES" >&2; exit 2 fi
Prevention
- Lowercase only; the switch is case-sensitive
- Cross-check available modes with `go tool cover -help` for your Go version
When it happens
Trigger: `go tool cover -mode=total` or `-mode=SET` (case-sensitive) or any unrecognized mode string.
Common situations: Misspelling a mode name. Using an uppercase variant. Assuming an older/newer mode name exists on this toolchain version (regonly/testmain were added later).
Related errors
- -var: %q is not a valid identifier
- %s: pkgconfig requires perblock/perfunc value
- too many options
- 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/f01831aaf9dd6bfd.
Report an issue: GitHub.