LemmyNet/lemmy · error
Failed to construct regex: {e}
Error message
Failed to construct regex: {e} What it means
Validation error in slur_regex: compiling the slur-filter Regex (built from the local site's slur_filter_regex setting) failed, or the cached build failed. It fires when the admin-configured regex in local_site.slur_filter_regex is invalid, or when try_get_with propagates a concurrent-build failure; the input at fault is the site's slur_filter_regex value.
Source
Thrown at crates/api/api_utils/src/utils.rs:410
}
pub async fn slur_regex(context: &LemmyContext) -> LemmyResult<Regex> {
static CACHE: CacheLock<Regex> = LazyLock::new(|| {
Cache::builder()
.max_capacity(1)
.time_to_live(CACHE_DURATION_FEDERATION)
.build()
});
Ok(
Box::pin(CACHE.try_get_with((), async {
let local_site = SiteView::read_local(&mut context.pool())
.await
.ok()
.map(|s| s.local_site);
build_and_check_regex(local_site.and_then(|s| s.slur_filter_regex).as_deref())
}))
.await
.map_err(|e| anyhow::anyhow!("Failed to construct regex: {e}"))?,
)
}
pub async fn get_url_blocklist(context: &LemmyContext) -> LemmyResult<RegexSet> {
static URL_BLOCKLIST: CacheLock<RegexSet> = LazyLock::new(|| {
Cache::builder()
.max_capacity(1)
.time_to_live(CACHE_DURATION_FEDERATION)
.build()
});
Ok(
URL_BLOCKLIST
.try_get_with::<_, LemmyError>((), async {
let urls = LocalSiteUrlBlocklist::get_all(&mut context.pool()).await?;
// The urls are already validated on saving, so just escape them.
// If this regex creation changes it must be synced withView on GitHub (pinned to 439734dd63)
Solutions
- Check the local site's slur_filter_regex setting and correct invalid regex syntax.
- Inspect the wrapped cause `e` to distinguish an invalid regex from a cache/concurrency failure.
- Clear or wait out the cache TTL after fixing the regex so a good value is rebuilt.
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at crates/api/api_utils/src/utils.rs:410 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of LemmyNet/lemmy@439734dd63 (2026-09-06).
Data as JSON: /api/errors/893bd5e74f54a9f2.
Report an issue: GitHub.