{"record":{"id":"33fc903e7a045b88","repo":"air-verse/air","slug":"failed-to-compile-regex-q-w","errorCode":null,"errorMessage":"failed to compile regex %q: %w","messagePattern":"failed to compile regex %q: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"runner/config.go","lineNumber":704,"sourceCode":"\t}\n\n\tadaptToVariousPlatforms(c)\n\tc.Build.normalizeIncludeDirs(c.Root)\n\tif err = c.Build.normalizeRules(c.Root); err != nil {\n\t\treturn err\n\t}\n\n\t// Join runtime arguments with the configuration arguments\n\truntimeArgs := flag.Args()\n\tc.Build.ArgsBin = append(c.Build.ArgsBin, runtimeArgs...)\n\n\t// Compile the exclude regexes if there are any patterns in the config file\n\tif len(c.Build.ExcludeRegex) > 0 {\n\t\tregexCompiled := make([]*regexp.Regexp, len(c.Build.ExcludeRegex))\n\t\tfor idx, expr := range c.Build.ExcludeRegex {\n\t\t\tre, err := regexp.Compile(expr)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to compile regex %q: %w\", expr, err)\n\t\t\t}\n\t\t\tregexCompiled[idx] = re\n\t\t}\n\t\tc.Build.regexCompiled = regexCompiled\n\t}\n\n\tc.Build.ExcludeDir = ed\n\n\t// Set colorful output, see https://github.com/fatih/color#disableenable-color\n\tswitch c.Color.Mode {\n\tcase \"always\":\n\t\tcolor.NoColor = false\n\tcase \"never\":\n\t\tcolor.NoColor = true\n\tcase \"auto\", \"\":\n\t\tbreak\n\tdefault:\n\t\treturn fmt.Errorf(\"unsupported color mode: %s. Expected always, auto, or never\", c.Color.Mode)","sourceCodeStart":686,"sourceCodeEnd":722,"githubUrl":"https://github.com/air-verse/air/blob/71ea1dee05248122ed22b5870c7fb20a90d80ddd/runner/config.go#L686-L722","documentation":"Air compiles each pattern in Build.ExcludeRegex into a *regexp.Regexp during config validation. If any pattern is not valid Go RE2 syntax, startup aborts with this error wrapping the regexp error.","triggerScenarios":"Setting `exclude_regex` in .air.toml to a string with invalid regex syntax (unbalanced parenthesis/bracket, invalid escape like \\d in wrong context, trailing backslash) — regexp.Compile fails and the error is returned.","commonSituations":"Porting PCRE-only constructs like lookaheads (?=...) or backreferences, which Go regexp does not support; escaping mistakes after TOML string processing; typos like `(foo|bar` with a missing close paren.","solutions":["Fix the pattern reported by %q so it is valid Go regexp (RE2) syntax","Replace unsupported PCRE features (lookaheads, backreferences) with RE2-compatible alternatives","Test the pattern first with a small Go snippet or playground using regexp.Compile","Escape backslashes properly inside TOML literal strings (use single quotes: exclude_regex = ['\\.foo$'])"],"exampleFix":"// before (.air.toml)\nexclude_regex = [\"(foo|bar\"]\n// after\nexclude_regex = [\"^(foo|bar)$\"]","handlingStrategy":"validation","validationCode":"// pre-validate exclude_regex entries\nfor _, expr := range excludeRegex {\n\tif _, err := regexp.Compile(expr); err != nil {\n\t\treturn fmt.Errorf(\"bad exclude_regex %q: %w\", expr, err)\n\t}\n}","typeGuard":null,"tryCatchPattern":"if err := cfg.Validate(); err != nil {\n\tif strings.Contains(err.Error(), \"failed to compile regex\") {\n\t\tlog.Fatalf(\"fix exclude_regex pattern: %v\", err)\n\t}\n\tlog.Fatal(err)\n}","preventionTips":["Test patterns with Go's regexp before adding them to config","Remember Go uses RE2: no lookaheads/lookbehinds/backreferences","Use TOML literal strings (single quotes) to avoid double-escaping backslashes","Keep patterns simple; prefer exclude_dir/exclude_file over regex where possible"],"tags":["config","regex","validation"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"71ea1dee05248122ed22b5870c7fb20a90d80ddd","analyzedAt":"2026-08-31T20:27:54.676Z","schemaVersion":2},"datasetVersion":"2026-09-01T03:17:15.561Z"}