quickwit-oss/quickwit · info

The regular expression should compile.

Error message

The regular expression should compile.

What it means

This panic fires from `.expect()` on `Regex::new` inside `parse_azure_uri`, which matches URIs of the form `azure://container/prefix`. The pattern is a static constant and is known to compile, so the expect documents that a bad regex is a programming error, not a runtime condition. A `None` from this function normally means the URI simply did not match the azure scheme.

Source

Thrown at quickwit/quickwit-storage/src/object_storage/azure_blob_storage.rs:589

) -> ContainerClient {
    let mut builder = ClientBuilder::new(storage_account_name.clone(), storage_credentials);
    if let Some(uri) = blob_service_uri {
        info!(endpoint=%uri, "using Azure blob storage endpoint defined in storage config or environment variable");
        builder = builder.cloud_location(CloudLocation::Custom {
            account: storage_account_name,
            uri,
        });
    }
    builder
        .blob_service_client()
        .container_client(container_name)
}

pub fn parse_azure_uri(uri: &Uri) -> Option<(String, PathBuf)> {
    // Ex: azure://container/prefix.
    static URI_PTN: LazyLock<Regex> = LazyLock::new(|| {
        Regex::new(r"azure(\+[^:]+)?://(?P<container>[^/]+)(/(?P<prefix>.+))?")
            .expect("The regular expression should compile.")
    });

    let captures = URI_PTN.captures(uri.as_str())?;

    let container = captures.name("container")?.as_str().to_string();
    let prefix = captures
        .name("prefix")
        .map(|prefix_match| PathBuf::from(prefix_match.as_str()))
        .unwrap_or_default();
    Some((container, prefix))
}

/// Collect a download stream into a single [`Bytes`].
///
/// `Bytes` segments yielded by the SDK are preserved so that the single-segment case avoids the
/// extra copy into a contiguous buffer. When more than one segment is received, they are
/// concatenated exactly once into a freshly allocated `Bytes`.
async fn download_all(

View on GitHub (pinned to a39730c5cd)

Solutions

  1. No runtime fix needed: the shipped regex compiles.
  2. If editing the pattern, run `cargo test -p quickwit-storage test_parse_azure_uri` to force initialization and catch a broken regex immediately.
  3. For user-supplied regexes elsewhere, use `Regex::new(p).map_err(...)` instead of expect.
Defensive patterns

Strategy: type-guard

Validate before calling

// Callers: treat None as an unsupported URI scheme before using the storage
let (container, path) = parse_azure_uri(&uri)
    .ok_or_else(|| anyhow::anyhow!("not a valid azure storage URI: {}", uri))?;

Type guard

fn is_azure_uri(uri: &Uri) -> bool {
    uri.scheme_str().map(|s| s.starts_with("azure")).unwrap_or(false)
}

Try / catch

// The expect panics rather than returning an error; guard by checking the scheme first
if !is_azure_uri(&uri) { bail!("URI is not azure://, cannot build AzureBlobStorage"); }

Prevention

When it happens

Trigger: Only if the static regex literal is edited to an invalid pattern (e.g. an unbalanced parenthesis or bad escape during a code change), causing `Regex::new` to return `Err`. Passing a non-azure URI never triggers it — that path returns `None` via `captures(...)?`.

Common situations: Not hit by library users. Developers contributing to quickwit encounter this pattern when modifying the URI regex in `parse_azure_uri`; a typo in the pattern panics on the first `LazyLock` initialization.

Related errors


AI-assisted analysis of quickwit-oss/quickwit@a39730c5cd (2026-09-08). Data as JSON: /api/errors/fbec5254a856fc55. Report an issue: GitHub.