quickwit-oss/quickwit · info

The regular expression should compile.

Error message

The regular expression should compile.

What it means

This panic is raised by `.expect()` on `Regex::new` for the static Google Cloud Storage URI pattern (`gs://bucket/prefix`) in `parse_google_uri`. Because the regex is a hardcoded constant that is known to compile, the expect signals a programming error only; valid runtime input never reaches the panic. URIs that do not match simply cause the function to return `None`.

Source

Thrown at quickwit/quickwit-storage/src/opendal_storage/google_cloud_storage.rs:101

    })?;

    let mut cfg = opendal::services::Gcs::default()
        .bucket(&bucket_name)
        .root(&prefix.to_string_lossy());

    if let Some(credential_path) = google_cloud_storage_config.resolve_credential_path() {
        info!(path=%credential_path, "fetching google cloud storage credentials from path");
        cfg = cfg.credential_path(&credential_path);
    }
    let store = OpendalStorage::new_google_cloud_storage(uri.clone(), cfg)?;
    Ok(store)
}

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

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

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

#[cfg(test)]
mod tests {
    use std::collections::BTreeMap;
    use std::path::Path;
    use std::sync::Arc;

View on GitHub (pinned to a39730c5cd)

Solutions

  1. No runtime fix needed: the shipped regex compiles.
  2. After editing the pattern, run `cargo test -p quickwit-storage test_parse_google_uri` to force initialization and detect breakage immediately.
  3. For dynamic regex sources, replace expect with `Regex::new(p).map_err(...)`.
Defensive patterns

Strategy: type-guard

Validate before calling

// Callers: treat None as an unsupported GCS URI before use
let (bucket, path) = parse_google_uri(&uri)
    .ok_or_else(|| anyhow::anyhow!("not a valid gs:// storage URI: {}", uri))?;

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Only when the static regex literal is modified into an invalid pattern (unbalanced groups, bad escape, trailing `$` misuse) during a code change; `LazyLock` then panics at first access. Passing a non-gs URI at runtime returns `None` instead and callers like `from_uri` surface an unsupported-scheme error.

Common situations: Not encountered by library users. Contributors touching the GCS URI parsing hit it during refactoring; a typo panics on first use in `test_parse_google_uri` or at storage startup.

Related errors


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