{"record":{"id":"4ce71cd5198dea83","repo":"cocoindex-io/cocoindex","slug":"invalid-exclude-reference-patterns-regex","errorCode":null,"errorMessage":"invalid exclude_reference_patterns regex","messagePattern":"invalid exclude_reference_patterns regex","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"rust/code_ast/src/elements/config.rs","lineNumber":134,"sourceCode":"}\n\nimpl CompiledLanguageConfig {\n    fn new(config: LanguageExtractorConfig) -> Self {\n        let exclude_regex = if config.exclude_reference_patterns.is_empty() {\n            None\n        } else {\n            // Each pattern is wrapped in a non-capturing group and the whole expression\n            // is anchored with ^ and $ so patterns match the full `referenced_full_path`.\n            // Users write e.g. `[A-Z]` instead of `^[A-Z]$`.\n            let alternatives: Vec<String> = config\n                .exclude_reference_patterns\n                .iter()\n                .map(|p| format!(\"(?:{p})\"))\n                .collect();\n            let combined = alternatives.join(\"|\");\n            Some(\n                Regex::new(&format!(\"^(?:{combined})$\"))\n                    .expect(\"invalid exclude_reference_patterns regex\"),\n            )\n        };\n        Self {\n            config,\n            exclude_regex,\n        }\n    }\n\n    /// Returns true if the given `referenced_full_path` should be excluded.\n    pub fn is_excluded(&self, full_path: &str) -> bool {\n        self.exclude_regex\n            .as_ref()\n            .is_some_and(|re| re.is_match(full_path))\n    }\n}\n\n// ── ExtractorConfig ────────────────────────────────────────────────────────\n","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/rust/code_ast/src/elements/config.rs#L116-L152","documentation":"Building a Config element, the exclude_reference_patterns entries are combined into a single anchored regex; if that combined pattern is not a valid regex, Regex::new panics via .expect(\"invalid exclude_reference_patterns regex\"). Because patterns are wrapped as (?:p) and joined with |, an individually valid-looking pattern can still fail or the combined alternation can exceed regex limits.","triggerScenarios":"Passing a syntactically invalid regex string in exclude_reference_patterns (e.g. \"[unclosed\", \"a)**\"), or a set of patterns whose combined alternation is invalid or too large for the regex crate's compiled-size limit.","commonSituations":"Users copying shell globs (e.g. \"*.py\") where regex is expected without escaping the `*`; typos in character classes; very long exclusion lists blowing the default regex size cap.","solutions":["Validate each pattern with Regex::new in a scratch test or an online regex checker (Rust/regex syntax) before configuring.","Escape regex metacharacters for literal matching (use \\. for dots, \\* etc.).","Split an overly large exclusion list into multiple configs or simplify patterns to reduce compiled size.","Remove the offending pattern from exclude_reference_patterns and rerun."],"exampleFix":"// before\nexclude_reference_patterns: [\"*.pyc\"]  // invalid regex\n\n// after\nexclude_reference_patterns: [\".*\\\\.pyc\"]","handlingStrategy":"validation","validationCode":"// validate patterns before configuring\nfor p in &patterns {\n    regex::Regex::new(&format!(\"(?:{p})\")).expect(&format!(\"bad pattern: {p}\"));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Unit-test every exclude pattern with Regex::new before shipping config.","Remember fields are regex, not globs — escape `.` and `*` for literals.","Keep exclusion lists short to stay within regex compile size limits."],"tags":["rust","regex","panic","config"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}