{"record":{"id":"74f3ea098a4c813e","repo":"air-verse/air","slug":"build-rules-d-s-failed-to-compile-regex-q","errorCode":null,"errorMessage":"build.rules[%d] (%s): failed to compile regex %q: %w","messagePattern":"build\\.rules\\[(.+?)\\] \\((.+?)\\): failed to compile regex %q: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"runner/config.go","lineNumber":198,"sourceCode":"\t\t\treturn fmt.Errorf(\"build.rules[%d] (%s): at least one of include_dir, include_ext or include_file is required\", i, r.Name)\n\t\t}\n\t\tr.includeDirAbs = r.includeDirAbs[:0]\n\t\tfor _, dir := range r.IncludeDir {\n\t\t\tdir = cleanPath(dir)\n\t\t\tif dir == \"\" {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tabs := filepath.Clean(dir)\n\t\t\tif !filepath.IsAbs(abs) {\n\t\t\t\tabs = filepath.Join(root, abs)\n\t\t\t}\n\t\t\tr.includeDirAbs = append(r.includeDirAbs, filepath.Clean(abs))\n\t\t}\n\t\tr.regexCompiled = r.regexCompiled[:0]\n\t\tfor _, expr := range r.ExcludeRegex {\n\t\t\tre, err := regexp.Compile(expr)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"build.rules[%d] (%s): failed to compile regex %q: %w\", i, r.Name, expr, err)\n\t\t\t}\n\t\t\tr.regexCompiled = append(r.regexCompiled, re)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc (c *cfgBuild) normalizeIncludeDirs(root string) {\n\tc.includeDirAbs = c.includeDirAbs[:0]\n\tc.extraIncludeDirs = c.extraIncludeDirs[:0]\n\tif root == \"\" {\n\t\treturn\n\t}\n\tfor _, dir := range c.IncludeDir {\n\t\tdir = cleanPath(dir)\n\t\tif dir == \"\" {\n\t\t\tcontinue\n\t\t}","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/air-verse/air/blob/71ea1dee05248122ed22b5870c7fb20a90d80ddd/runner/config.go#L180-L216","documentation":"Each rule's exclude_regex entries are compiled with regexp.Compile during config normalization; an invalid Go regular expression aborts loading with the failing pattern and the underlying regex error wrapped via %w.","triggerScenarios":"A `.air.toml` rule with exclude_regex containing invalid syntax, e.g. unbalanced parentheses `(foo`, a bad escape `\\q`, or a stray `*`, when the config is loaded.","commonSituations":"Copying PCRE/JS-flavored regex not supported by Go's RE2 (e.g. lookaheads `(?=...)`, backreferences); hand-editing a pattern and dropping a bracket; escaping mistakes in TOML strings.","solutions":["Fix the regex syntax reported in the wrapped error; test with regexp.Compile or play.golang.org","Replace unsupported constructs (lookaheads/backreferences) with RE2-compatible patterns","Escape backslashes properly in the TOML string"],"exampleFix":"// before (.air.toml)\nexclude_regex = [\"_test(?=\\.go)$\"]\n// after (.air.toml)\nexclude_regex = [\"_test\\.go$\"]","handlingStrategy":"validation","validationCode":"package main\n\nimport (\n    \"fmt\"\n    \"regexp\"\n    \"os\"\n)\n\nfunc main() {\n    for _, expr := range []string{\"_test\\\\.go$\"} { // patterns from .air.toml exclude_regex\n        if _, err := regexp.Compile(expr); err != nil {\n            fmt.Fprintf(os.Stderr, \"invalid exclude_regex %q: %v\\n\", expr, err)\n            os.Exit(1)\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Test exclude_regex patterns against Go's regexp (RE2) before adding them","Avoid lookaheads/lookbehinds and backreferences — RE2 does not support them","Escape backslashes correctly inside TOML strings"],"tags":["config","regex","validation","rules"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"71ea1dee05248122ed22b5870c7fb20a90d80ddd","analyzedAt":"2026-08-31T20:27:54.676Z","schemaVersion":2},"datasetVersion":"2026-09-01T03:17:15.561Z"}