{"record":{"id":"f998dda8e19bd0bf","repo":"golang/go","slug":"no-match-for-q-in-s","errorCode":null,"errorMessage":"no match for %#q in %s","messagePattern":"no match for %#q in (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/script/cmds.go","lineNumber":702,"sourceCode":"\tif isGrep {\n\t\tname = args[1] // for error messages\n\t\tdata, err := os.ReadFile(s.Path(args[1]))\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\ttext = string(data)\n\t}\n\n\tif n > 0 {\n\t\tcount := len(re.FindAllString(text, -1))\n\t\tif count != n {\n\t\t\treturn fmt.Errorf(\"found %d matches for %#q in %s\", count, pattern, name)\n\t\t}\n\t\treturn nil\n\t}\n\n\tif !re.MatchString(text) {\n\t\treturn fmt.Errorf(\"no match for %#q in %s\", pattern, name)\n\t}\n\n\tif !quiet {\n\t\t// Print the lines containing the match.\n\t\tloc := re.FindStringIndex(text)\n\t\tfor loc[0] > 0 && text[loc[0]-1] != '\\n' {\n\t\t\tloc[0]--\n\t\t}\n\t\tfor loc[1] < len(text) && text[loc[1]] != '\\n' {\n\t\t\tloc[1]++\n\t\t}\n\t\tlines := strings.TrimSuffix(text[loc[0]:loc[1]], \"\\n\")\n\t\ts.Logf(\"matched: %s\\n\", lines)\n\t}\n\treturn nil\n}\n\n// Help writes command documentation to the script log.","sourceCodeStart":684,"sourceCodeEnd":720,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/script/cmds.go#L684-L720","documentation":"Thrown by the match function (Grep/Stdout/Stderr commands) when the regexp pattern does not match anywhere in the target text and -count=N was not specified. re.MatchString returns false. The %#q shows the pattern and %s shows the target name. This is the basic 'pattern must appear at least once' assertion.","triggerScenarios":"re.MatchString(text) returns false — the compiled regexp finds no match in stdout, stderr, or the grep target file. No -count constraint was set (n == 0), so the default 'at least one match' expectation applies.","commonSituations":"Program output changed so an expected line no longer appears. Regex pattern is wrong (escaping issues, wrong anchors, case sensitivity). Output went to stderr instead of stdout (or vice versa). Platform-specific output differs from what the test expects.","solutions":["Run with -v to see actual stdout/stderr and compare against the expected pattern.","Fix the regex if it's too strict — check anchors, character classes, and escaping.","Verify the output stream: the pattern may be on stderr, not stdout (use stderr instead of stdout).","If the program's output legitimately changed, update the expected pattern to match."],"exampleFix":"// Before: stdout 'BUILD SUCCESSFUL'\n// After:  stdout 'build completed'  // if message wording changed\n\n// Or check the right stream:\n// stderr 'error:'  // instead of stdout","handlingStrategy":"validation","validationCode":"// Pre-test: verify the pattern matches expected output:\nfunc verifyPattern(text, pattern string) error {\n    re, err := regexp.Compile(pattern)\n    if err != nil { return err }\n    if !re.MatchString(text) {\n        return fmt.Errorf(\"pattern %q does not match output\", pattern)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run tests with -v to inspect actual stdout/stderr when patterns fail.","Verify the regex pattern is correct (anchors, escaping, case sensitivity).","Confirm output goes to the expected stream (stdout vs stderr).","Update patterns when program output wording legitimately changes."],"tags":["script","test-framework","grep","no-match","assertion","go-compiler-internal"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}