LemmyNet/lemmy · error

Failed to build URL blocklist due to `{}`

Error message

Failed to build URL blocklist due to `{}`

What it means

Validation error in get_url_blocklist: building the RegexSet from the LocalSiteUrlBlocklist entries failed (RegexSet::new returned an error). It fires when URL blocklist rows cannot be combined into a valid regex set — e.g. unexpected pattern content in a saved blocklist URL; the input at fault is the blocklist URL rows read from the database.

Source

Thrown at crates/api/api_utils/src/utils.rs:436

      .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 with
        // lemmy_utils::utils::markdown::create_url_blocklist_test_regex_set.
        let regexes = urls.iter().map(|url| format!(r"\b{}\b", escape(&url.url)));

        let set = RegexSet::new(regexes)?;
        Ok(set)
      })
      .await
      .map_err(|e| anyhow::anyhow!("Failed to build URL blocklist due to `{}`", e))?,
  )
}

// `local_site` is optional so that tests work easily
pub fn check_nsfw_allowed(nsfw: Option<bool>, local_site: Option<&LocalSite>) -> LemmyResult<()> {
  let is_nsfw = nsfw.unwrap_or_default();
  let nsfw_disallowed = local_site.is_some_and(|s| s.nsfw_content_disallowed);

  if nsfw_disallowed && is_nsfw {
    return Err(LemmyErrorType::NsfwNotAllowed.into());
  }

  Ok(())
}

/// Read the site for an ap_id.
///
/// Used for GetCommunityResponse and GetPersonDetails

View on GitHub (pinned to 439734dd63)

Solutions

  1. Review the local site URL blocklist rows for patterns that break RegexSet compilation and correct or remove them.
  2. Inspect the inner error to identify the offending regex entry.
  3. Re-validate blocklist URLs on save so invalid patterns never reach this builder.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/api/api_utils/src/utils.rs:436 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/18c5016c33535c15. Report an issue: GitHub.