{"record":{"id":"f8c2e28256663b2c","repo":"golang/go","slug":"bad-count-v","errorCode":null,"errorMessage":"bad -count=: %v","messagePattern":"bad -count=: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/script/cmds.go","lineNumber":655,"sourceCode":"\t\t\t\t\"The -q flag suppresses printing of matches.\",\n\t\t\t},\n\t\t\tRegexpArgs: firstNonFlag,\n\t\t},\n\t\tfunc(s *State, args ...string) (WaitFunc, error) {\n\t\t\treturn nil, match(s, args, \"\", \"grep\")\n\t\t})\n}\n\nconst matchUsage = \"[-count=N] [-q] 'pattern'\"\n\n// match implements the Grep, Stdout, and Stderr commands.\nfunc match(s *State, args []string, text, name string) error {\n\tn := 0\n\tif len(args) >= 1 && strings.HasPrefix(args[0], \"-count=\") {\n\t\tvar err error\n\t\tn, err = strconv.Atoi(args[0][len(\"-count=\"):])\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"bad -count=: %v\", err)\n\t\t}\n\t\tif n < 1 {\n\t\t\treturn fmt.Errorf(\"bad -count=: must be at least 1\")\n\t\t}\n\t\targs = args[1:]\n\t}\n\tquiet := false\n\tif len(args) >= 1 && args[0] == \"-q\" {\n\t\tquiet = true\n\t\targs = args[1:]\n\t}\n\n\tisGrep := name == \"grep\"\n\n\twantArgs := 1\n\tif isGrep {\n\t\twantArgs = 2\n\t}","sourceCodeStart":637,"sourceCodeEnd":673,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/script/cmds.go#L637-L673","documentation":"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.","triggerScenarios":"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\".","commonSituations":"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.","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."],"exampleFix":"// Before (broken): stdout -count=three 'pattern'\n// After (fixed):  stdout -count=3 'pattern'","handlingStrategy":"validation","validationCode":"// Validate -count flag value before the match command:\nfunc validateCountFlag(arg string) error {\n    if !strings.HasPrefix(arg, \"-count=\") { return nil }\n    val := arg[len(\"-count=\"):]\n    n, err := strconv.Atoi(val)\n    if err != nil {\n        return fmt.Errorf(\"-count must be an integer, got %q: %w\", val, err)\n    }\n    if n < 1 {\n        return fmt.Errorf(\"-count must be >= 1, got %d\", n)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["script","test-framework","grep","count-flag","parse-error","go-compiler-internal"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}