Hmbown/CodeWhale · error
anchor regex
Error message
anchor regex
What it means
This expect guards the one-time compilation of the ANCHOR_RE static pattern (<a href=...> extraction) inside OnceLock::get_or_init. It fires only if the hardcoded literal regex is invalid — a programmer error caught at first use, not a runtime-input failure. A panic here means the HTML parsing module shipped a broken pattern.
Source
Thrown at crates/tui/src/tools/web_run.rs:1347
total_pages: pages.len(),
content,
})
}
// === HTML Parsing ===
static ANCHOR_RE: OnceLock<Regex> = OnceLock::new();
static TAG_RE: OnceLock<Regex> = OnceLock::new();
static BLOCK_RE: OnceLock<Regex> = OnceLock::new();
static SCRIPT_RE: OnceLock<Regex> = OnceLock::new();
static STYLE_RE: OnceLock<Regex> = OnceLock::new();
static TITLE_RE: OnceLock<Regex> = OnceLock::new();
static MARKDOWN_LINK_RE: OnceLock<Regex> = OnceLock::new();
fn get_anchor_re() -> &'static Regex {
ANCHOR_RE.get_or_init(|| {
Regex::new(r#"(?is)<a\s+[^>]*href\s*=\s*['\"]([^'\"]+)['\"][^>]*>(.*?)</a>"#)
.expect("anchor regex")
})
}
fn get_tag_re() -> &'static Regex {
TAG_RE.get_or_init(|| Regex::new(r"<[^>]+>").expect("tag regex"))
}
fn get_block_re() -> &'static Regex {
BLOCK_RE.get_or_init(|| {
Regex::new(r"(?is)</?(p|div|li|ul|ol|br|h[1-6]|tr|td|th|table|section|article)[^>]*>")
.expect("block regex")
})
}
fn get_script_re() -> &'static Regex {
SCRIPT_RE.get_or_init(|| Regex::new(r"(?is)<script[^>]*>.*?</script>").unwrap())
}
View on GitHub (pinned to 0c42157ee5)
Solutions
- Validate the pattern in a test (Regex::new in a #[test]) so CI catches a bad literal before runtime
- Never build ANCHOR_RE from dynamic input; keep it a compile-time literal
- If a pattern ever needs to change, run cargo test -p codewhale-tui to exercise get_anchor_re
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/tui/src/tools/web_run.rs:1347 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20).
Data as JSON: /api/errors/436a5a6ee8e0d498.
Report an issue: GitHub.