cocoindex-io/cocoindex · critical
invalid exclude_reference_patterns regex
Error message
invalid exclude_reference_patterns regex
What it means
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.
Source
Thrown at rust/code_ast/src/elements/config.rs:134
}
impl CompiledLanguageConfig {
fn new(config: LanguageExtractorConfig) -> Self {
let exclude_regex = if config.exclude_reference_patterns.is_empty() {
None
} else {
// Each pattern is wrapped in a non-capturing group and the whole expression
// is anchored with ^ and $ so patterns match the full `referenced_full_path`.
// Users write e.g. `[A-Z]` instead of `^[A-Z]$`.
let alternatives: Vec<String> = config
.exclude_reference_patterns
.iter()
.map(|p| format!("(?:{p})"))
.collect();
let combined = alternatives.join("|");
Some(
Regex::new(&format!("^(?:{combined})$"))
.expect("invalid exclude_reference_patterns regex"),
)
};
Self {
config,
exclude_regex,
}
}
/// Returns true if the given `referenced_full_path` should be excluded.
pub fn is_excluded(&self, full_path: &str) -> bool {
self.exclude_regex
.as_ref()
.is_some_and(|re| re.is_match(full_path))
}
}
// ── ExtractorConfig ────────────────────────────────────────────────────────
View on GitHub (pinned to e84aa99b32)
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.
Example fix
// before exclude_reference_patterns: ["*.pyc"] // invalid regex // after exclude_reference_patterns: [".*\\.pyc"]
Defensive patterns
Strategy: validation
Validate before calling
// validate patterns before configuring
for p in &patterns {
regex::Regex::new(&format!("(?:{p})")).expect(&format!("bad pattern: {p}"));
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- valid tokenizer regex
- Environment::provide: type `{}` has already been provided
- Environment::provide_key({}): {e}
- with_base_url must be called before the connection is shared
- Invalid Neo4j database name: {database!r}. Must match [A-Za-
AI-assisted analysis of cocoindex-io/cocoindex@e84aa99b32 (2026-09-08).
Data as JSON: /api/errors/4ce71cd5198dea83.
Report an issue: GitHub.