zed-industries/zed · error
Failed to create REGEX
Error message
Failed to create REGEX
What it means
A static-initialization guard: link_pattern_file_candidates compiles a fixed Regex via LazyLock and expects it to succeed. Regex::new on a hardcoded literal only fails if the pattern itself is malformed, so this panic indicates a programming error in the committed pattern string, not any user input or runtime condition — the regex is compiled once per process from a constant.
Source
Thrown at crates/editor/src/hover_links.rs:910
row: parsed.row,
column: parsed.column,
},
));
}
}
}
}
}
None
}
// Generates candidate file paths by stripping common punctuation wrappers.
// Handles markdown patterns like [title](path), `path`, (path), as well as
// partial wrappers where punctuation only appears on one side (e.g. path) or path`).
// Returns candidates ordered from most-specific (most trimmed) to least-specific (raw).
fn link_pattern_file_candidates(candidate: &str) -> Vec<(String, Range<usize>)> {
static MD_LINK_REGEX: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"]\(([^)]*)\)").expect("Failed to create REGEX"));
// Punctuation that commonly wraps file paths in prose/markdown
const LEADING_PUNCTUATION: &[char] = &['`', '(', '[', '{', '<', '"', '\''];
const TRAILING_PUNCTUATION: &[char] = &[
'`', ')', ']', '}', '>', '"', '\'', '.', ',', ':', ';', '!', '?',
];
let candidate_len = candidate.len();
let mut candidates = Vec::new();
// Trim leading and trailing punctuation iteratively
let mut start = 0;
let mut end = candidate_len;
// Trim leading punctuation
for ch in candidate.chars() {
if LEADING_PUNCTUATION.contains(&ch) {
start += ch.len_utf8();View on GitHub (pinned to 9d272b0363)
Solutions
- Add a unit test that constructs the regex (exercises the LazyLock) so a bad pattern fails CI instead of at runtime
- Prefer a checked compile with a documented invariant comment, keeping expect only where a test guarantees it
- Use a regex crate macro (e.g. regex!) if available to validate at compile time
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/editor/src/hover_links.rs:910 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-08-20).
Data as JSON: /api/errors/b33105d6ce23dbaa.
Report an issue: GitHub.