tinyhumansai/openhuman · error
pattern rule regex is well-formed
Error message
pattern rule regex is well-formed
What it means
Static-invariant panic in pattern_rule(): the PII rule table embeds raw regex pattern strings, and Regex::new expects them to be well-formed. A failure means a developer typo in the pattern literal (unbalanced group, bad escape) at table-build time — not a user-input problem, since no runtime string reaches this constructor.
Source
Thrown at src/openhuman/security/pii/rules.rs:46
}
/// Build a keyword rule: a case-insensitive, word-boundaried alternation over
/// `terms`, all attributed to `category`.
fn keyword_rule(category: PiiCategory, terms: &[&str]) -> Rule {
let alternation = terms.join("|");
let pattern = format!(r"(?i)\b(?:{alternation})\b");
Rule {
category,
regex: Regex::new(&pattern).expect("keyword rule regex is well-formed"),
validator: None,
}
}
/// Build a pattern rule from a raw regex string.
fn pattern_rule(category: PiiCategory, pattern: &str, validator: Option<fn(&str) -> bool>) -> Rule {
Rule {
category,
regex: Regex::new(pattern).expect("pattern rule regex is well-formed"),
validator,
}
}
/// Luhn checksum validation for candidate payment-card numbers. Strips
/// separators first; requires 13–19 digits.
pub(crate) fn is_luhn_valid(raw: &str) -> bool {
let digits: Vec<u8> = raw
.bytes()
.filter(|b| b.is_ascii_digit())
.map(|b| b - b'0')
.collect();
if !(13..=19).contains(&digits.len()) {
return false;
}
let mut sum = 0u32;
// Double every second digit from the right.
for (i, &d) in digits.iter().rev().enumerate() {View on GitHub (pinned to 7491200858)
Solutions
- Fix the malformed pattern literal in the rule table
- Cover every pattern with a compile-time test that runs Regex::new over the table
- Lint pattern literals (clippy's regex checks) to catch drift before release
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at src/openhuman/security/pii/rules.rs:46 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tinyhumansai/openhuman@7491200858 (2026-08-17).
Data as JSON: /api/errors/bb1b72f6df1800bc.
Report an issue: GitHub.