Hmbown/CodeWhale · error

block regex

Error message

block regex

What it means

Compilation assertion for BLOCK_RE, the pattern matching block-level HTML tags (p, div, li, ul, ol, br, h1-6, table elements) used to insert line breaks when flattening pages. The expect fires only if the hardcoded literal is syntactically invalid — a programmer error, surfaced at the first html_to_text call.

Source

Thrown at crates/tui/src/tools/web_run.rs:1358

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())
}

fn get_style_re() -> &'static Regex {
    STYLE_RE.get_or_init(|| Regex::new(r"(?is)<style[^>]*>.*?</style>").unwrap())
}

fn get_title_re() -> &'static Regex {
    TITLE_RE.get_or_init(|| Regex::new(r"(?is)<title[^>]*>(.*?)</title>").unwrap())
}

fn parse_html(html: &str, base_url: &str) -> (Vec<String>, Vec<WebLink>, Option<String>) {
    let title = extract_title(html);
    let without_scripts = get_script_re().replace_all(html, "").to_string();

View on GitHub (pinned to 0c42157ee5)

Solutions

  1. Add a unit test touching get_block_re so bad literals break the build, not runtime
  2. Edit the pattern only with cargo test -p codewhale-tui run afterwards
  3. Keep the alternation group balanced when adding tag names
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/tui/src/tools/web_run.rs:1358 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/617f4f5e70000fbb. Report an issue: GitHub.