{"record":{"id":"41e428c590a335d8","repo":"Hmbown/CodeWhale","slug":"bing-snippet-regex-pattern-is-valid","errorCode":null,"errorMessage":"bing snippet regex pattern is valid","messagePattern":"bing snippet regex pattern is valid","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/web/scrape.rs","lineNumber":68,"sourceCode":"\nfn get_bing_result_re() -> &'static Regex {\n    BING_RESULT_RE.get_or_init(|| {\n        Regex::new(r#\"(?is)<li[^>]*class=\\\"[^\\\"]*\\bb_algo\\b[^\\\"]*\\\"[^>]*>(.*?)</li>\"#)\n            .expect(\"bing result regex pattern is valid\")\n    })\n}\n\nfn get_bing_title_re() -> &'static Regex {\n    BING_TITLE_RE.get_or_init(|| {\n        Regex::new(r#\"(?is)<h2[^>]*>.*?<a[^>]*href=\\\"([^\\\"]+)\\\"[^>]*>(.*?)</a>\"#)\n            .expect(\"bing title regex pattern is valid\")\n    })\n}\n\nfn get_bing_snippet_re() -> &'static Regex {\n    BING_SNIPPET_RE.get_or_init(|| {\n        Regex::new(r#\"(?is)<div[^>]*class=\\\"[^\\\"]*\\bb_caption\\b[^\\\"]*\\\"[^>]*>.*?<p[^>]*>(.*?)</p>\"#)\n            .expect(\"bing snippet regex pattern is valid\")\n    })\n}\n\n/// Parse DuckDuckGo HTML SERP results. Known spam-domain hits are omitted.\npub fn parse_duckduckgo_results(html: &str, max_results: usize) -> Vec<ScrapedSearchResult> {\n    let title_re = get_title_re();\n    let snippet_re = get_snippet_re();\n    let snippets: Vec<String> = snippet_re\n        .captures_iter(html)\n        .filter_map(|cap| cap.get(1).or_else(|| cap.get(2)))\n        .map(|m| normalize_text(m.as_str()))\n        .collect();\n\n    let mut results = Vec::new();\n    for (idx, cap) in title_re.captures_iter(html).enumerate() {\n        if results.len() >= max_results {\n            break;\n        }","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/tools/web/scrape.rs#L50-L86","documentation":"Panic compiling the Bing caption/snippet pattern `(?is)<div[^>]*class=\"[^\"]*\\bb_caption\\b[^\"]*\"[^>]*>.*?<p[^>]*>(.*?)</p>` in `BING_SNIPPET_RE.get_or_init`. Same family as the other scrape getters: a hardcoded literal whose only failure mode is a manual edit breaking regex syntax (flag group, `\\b` escapes, group balance), which makes `Regex::new` return `Err` and trips the expect on first use.","triggerScenarios":"Editing the caption literal for a Bing markup change and introducing a syntax error; the first Bing snippet extraction after that build panics inside `get_bing_snippet_re`.","commonSituations":"Bing markup variants where the caption div or inner `<p>` structure changes; hand-merging a pattern fix across branches and losing an escape.","solutions":["Fix the literal and validate it compiles standalone before committing.","Add the getter to the shared compile-all-patterns unit test.","Run `cargo test -p codewhale-tui --lib scrape` after any pattern change."],"exampleFix":"// before\nRegex::new(\n    r#\"(?is)<div[^>]*class=\\\"[^\\\"]*\\bb_caption\\b[^\\\"]*\\\"[^>]*>.*?<p[^>]*>(.*?)</p>\"#,\n).expect(\"bing snippet regex pattern is valid\")\n\n// after: guarded initialization in the shared test\n#[test]\nfn all_bing_snippet_edits_compile() {\n    let _ = get_bing_snippet_re();\n}","handlingStrategy":"validation","validationCode":"#[test]\nfn bing_snippet_pattern_compiles() {\n    let _ = get_bing_snippet_re();\n}","typeGuard":null,"tryCatchPattern":"let snippets = std::panic::catch_unwind(|| extract_bing_snippets(&html))\n    .unwrap_or_default();","preventionTips":["Keep the `\\b` word-boundary escapes intact when copying the literal between branches.","Run `cargo test -p codewhale-tui --lib scrape` after any SERP pattern change."],"tags":["rust","regex","bing","html-scraping","panic","expect"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}