golang/go · error
invalid count %q
Error message
invalid count %q
What it means
This error comes from the Go toolchain's custom `count` flag type, which powers the `-v` (verbose) flag. A count flag behaves like a bool when used bare (`-v` increments) but also accepts `-v=N` to set an explicit count. When `Set` receives a value that is not `"true"`, `"false"`, or a parseable integer, it returns this error.
Source
Thrown at src/cmd/internal/objabi/flag.go:260
// count is a flag.Value that is like a flag.Bool and a flag.Int.
// If used as -name, it increments the count, but -name=x sets the count.
// Used for verbose flag -v.
type count int
func (c *count) String() string {
return fmt.Sprint(int(*c))
}
func (c *count) Set(s string) error {
switch s {
case "true":
*c++
case "false":
*c = 0
default:
n, err := strconv.Atoi(s)
if err != nil {
return fmt.Errorf("invalid count %q", s)
}
*c = count(n)
}
return nil
}
func (c *count) Get() any {
return int(*c)
}
func (c *count) IsBoolFlag() bool {
return true
}
func (c *count) IsCountFlag() bool {
return true
}
View on GitHub (pinned to b6b368adc5)
Solutions
- Use `-v` alone to increment verbosity, or `-v=N` where N is an integer (e.g., `-v=2`).
- Remove any non-integer suffix or prefix from the flag value.
- Check the tool's `-d` help or source to confirm the flag type accepts only integer values.
Example fix
// before $ go build -v=yes ./... // after $ go build -v=2 ./... // or simply $ go build -v ./...
Defensive patterns
Strategy: validation
Validate before calling
// Validate count flag value before passing to the tool
func validateCountFlag(val string) error {
switch val {
case "true", "false":
return nil
default:
if _, err := strconv.Atoi(val); err != nil {
return fmt.Errorf("count flag must be 'true', 'false', or an integer, got %q", val)
}
return nil
}
} Prevention
- Use bare -v or -v=<integer> only — never -v=<non-numeric-string>.
- In scripts, always pass integer literals to count flags, never variables that might contain non-numeric data.
- Document flag types when wrapping Go tools in build scripts.
When it happens
Trigger: Passing `-v=<non-numeric>` (e.g., `-v=high`, `-v=2.5`, `-v=yes`) to any Go toolchain binary that registers a `count`-typed flag. The flag's `Set` method tries `strconv.Atoi(s)` and on failure returns the error.
Common situations: Misremembering the verbose flag syntax and writing `-v=on` or `-v=verbose` instead of `-v` or `-v=2`. Shell quoting issues passing a flag value that includes non-numeric characters. A build script or wrapper that dynamically injects a value into the count flag.
Related errors
- unknown debug key %s
- -C flag must be first flag on command line
- flag %q triggers external linking
- dwarf: null reference in %d
- failed to locate cmd/compile for target platform
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/638a0415c6a21229.
Report an issue: GitHub.