{"record":{"id":"76bdb5ad7a33cac9","repo":"kovidgoyal/kitty","slug":"failed-to-compile-the-regex-pattern-v-with-erro","errorCode":null,"errorMessage":"Failed to compile the regex pattern: %#v with error: %w","messagePattern":"Failed to compile the regex pattern: %#v with error: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kittens/hints/marks.go","lineNumber":659,"sourceCode":"\t}\n\tif self.Pattern != \"\" {\n\t\treturn fmt.Sprintf(\"No %s found with pattern: %s\", none_of, self.Pattern)\n\t}\n\treturn fmt.Sprintf(\"No %s found\", none_of)\n}\n\nfunc find_marks(text string, opts *Options, cli_args ...string) (sanitized_text string, ans []Mark, index_map map[int]*Mark, err error) {\n\tsanitized_text, hyperlinks := process_escape_codes(text)\n\tused_pattern := \"\"\n\n\trun_basic_matching := func() error {\n\t\tpattern, post_processors, group_processors, err := functions_for(opts)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tr, err := regexp2.Compile(pattern, regexp2.RE2)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to compile the regex pattern: %#v with error: %w\", pattern, err)\n\t\t}\n\t\tans = mark(r, post_processors, group_processors, sanitized_text, opts)\n\t\tused_pattern = pattern\n\t\treturn nil\n\t}\n\n\tif opts.CustomizeProcessing != \"\" {\n\t\tcmd := exec.Command(utils.KittyExe(), append([]string{\"+runpy\", \"from kittens.hints.main import custom_marking; custom_marking()\"}, cli_args...)...)\n\t\tcmd.Stdin = strings.NewReader(sanitized_text)\n\t\tstdout, stderr := bytes.Buffer{}, bytes.Buffer{}\n\t\tcmd.Stdout, cmd.Stderr = &stdout, &stderr\n\t\terr = cmd.Run()\n\t\tif err != nil {\n\t\t\tvar e *exec.ExitError\n\t\t\tif errors.As(err, &e) && e.ExitCode() == 2 {\n\t\t\t\terr = run_basic_matching()\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn","sourceCodeStart":641,"sourceCodeEnd":677,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kittens/hints/marks.go#L641-L677","documentation":"Thrown when the kitten hints custom regex (built from --hints-regex or a hint type's pattern via functions_for) fails to compile with regexp2 in RE2 mode. The pattern string is included with %#v so you can see exactly what was generated. Typically caused by invalid regex syntax or RE2-incompatible constructs.","triggerScenarios":"Passing an invalid regex via opts (e.g. --custom word character that builds a bad pattern), or a pattern using lookahead/lookbehind/backreferences which RE2 mode in regexp2 rejects.","commonSituations":"User-supplied --hints regex with a typo (unbalanced paren, trailing backslash), or PCRE-only constructs like (?=...) under regexp2.RE2 flag.","solutions":["Fix the reported pattern (printed with %#v) — correct syntax errors like unbalanced groups or escapes","If you need lookarounds/backreferences, remove the regexp2.RE2 flag or rewrite the pattern without them","Test the pattern separately with an RE2-compatible engine (e.g. Go's regexp package) before passing it to the kitten"],"exampleFix":"// before\nkitty @ kitten hints --custom 'foo(?=bar)'\n// after (RE2-safe)\nkitty @ kitten hints --custom 'foobar'","handlingStrategy":"validation","validationCode":"import \"regexp\"\nfunc validRE2(pattern string) bool {\n    _, err := regexp.Compile(pattern)\n    return err == nil\n}","typeGuard":null,"tryCatchPattern":"if err := find_marks(...); err != nil && strings.Contains(err.Error(), \"Failed to compile the regex pattern\") { /* surface pattern to user for editing */ }","preventionTips":["Validate user-supplied hint regexes with regexp.Compile before passing them to the kitten","Avoid lookarounds/backreferences since RE2 mode is used"],"tags":["regex","kitty","hints","regexp2","re2"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}