{"record":{"id":"638a0415c6a21229","repo":"golang/go","slug":"invalid-count-q","errorCode":null,"errorMessage":"invalid count %q","messagePattern":"invalid count %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/objabi/flag.go","lineNumber":260,"sourceCode":"// count is a flag.Value that is like a flag.Bool and a flag.Int.\n// If used as -name, it increments the count, but -name=x sets the count.\n// Used for verbose flag -v.\ntype count int\n\nfunc (c *count) String() string {\n\treturn fmt.Sprint(int(*c))\n}\n\nfunc (c *count) Set(s string) error {\n\tswitch s {\n\tcase \"true\":\n\t\t*c++\n\tcase \"false\":\n\t\t*c = 0\n\tdefault:\n\t\tn, err := strconv.Atoi(s)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"invalid count %q\", s)\n\t\t}\n\t\t*c = count(n)\n\t}\n\treturn nil\n}\n\nfunc (c *count) Get() any {\n\treturn int(*c)\n}\n\nfunc (c *count) IsBoolFlag() bool {\n\treturn true\n}\n\nfunc (c *count) IsCountFlag() bool {\n\treturn true\n}\n","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/objabi/flag.go#L242-L278","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n$ go build -v=yes ./...\n\n// after\n$ go build -v=2 ./...\n// or simply\n$ go build -v ./...","handlingStrategy":"validation","validationCode":"// Validate count flag value before passing to the tool\nfunc validateCountFlag(val string) error {\n    switch val {\n    case \"true\", \"false\":\n        return nil\n    default:\n        if _, err := strconv.Atoi(val); err != nil {\n            return fmt.Errorf(\"count flag must be 'true', 'false', or an integer, got %q\", val)\n        }\n        return nil\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["flags","compiler","linker","command-line"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}