golang/go · error
bad -count=: %v
Error message
bad -count=: %v
What it means
Thrown by the match function (backing Grep, Stdout, Stderr commands) in the Go test script framework when the -count=N flag value cannot be parsed as an integer. strconv.Atoi fails on the substring after "-count=". The %v wraps the strconv error.
Source
Thrown at src/cmd/internal/script/cmds.go:655
"The -q flag suppresses printing of matches.",
},
RegexpArgs: firstNonFlag,
},
func(s *State, args ...string) (WaitFunc, error) {
return nil, match(s, args, "", "grep")
})
}
const matchUsage = "[-count=N] [-q] 'pattern'"
// match implements the Grep, Stdout, and Stderr commands.
func match(s *State, args []string, text, name string) error {
n := 0
if len(args) >= 1 && strings.HasPrefix(args[0], "-count=") {
var err error
n, err = strconv.Atoi(args[0][len("-count="):])
if err != nil {
return fmt.Errorf("bad -count=: %v", err)
}
if n < 1 {
return fmt.Errorf("bad -count=: must be at least 1")
}
args = args[1:]
}
quiet := false
if len(args) >= 1 && args[0] == "-q" {
quiet = true
args = args[1:]
}
isGrep := name == "grep"
wantArgs := 1
if isGrep {
wantArgs = 2
}View on GitHub (pinned to b6b368adc5)
Solutions
- Provide a valid positive integer after -count=, e.g. `-count=3`.
- Double-check for typos in the flag value.
- Do not use hex (0x) or float notation — only plain decimal integers are accepted.
Example fix
// Before (broken): stdout -count=three 'pattern' // After (fixed): stdout -count=3 'pattern'
Defensive patterns
Strategy: validation
Validate before calling
// Validate -count flag value before the match command:
func validateCountFlag(arg string) error {
if !strings.HasPrefix(arg, "-count=") { return nil }
val := arg[len("-count="):]
n, err := strconv.Atoi(val)
if err != nil {
return fmt.Errorf("-count must be an integer, got %q: %w", val, err)
}
if n < 1 {
return fmt.Errorf("-count must be >= 1, got %d", n)
}
return nil
} Prevention
- Always use a plain positive decimal integer for -count=N.
- Double-check flag spelling and value for typos.
- Do not use hex, float, or symbolic notation for -count.
When it happens
Trigger: The first argument starts with "-count=" but the remainder is not a valid base-10 integer. E.g. "-count=abc", "-count=", "-count=1.5", or "-count=0x3".
Common situations: Typo in the -count flag value in a test script, or using hex/float notation instead of decimal. Also a stray equals sign or missing number after the flag.
Related errors
- bad -count=: must be at least 1
- found %d matches for %#q in %s
- no match for %#q in %s
- invalid mode: %s
- %s and %s differ
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/f8c2e28256663b2c.
Report an issue: GitHub.