quickwit-oss/quickwit · info
The regular expression should compile.
Error message
The regular expression should compile.
What it means
This panic comes from `.expect()` on `Regex::new` for the static S3 URI pattern (`s3://bucket/prefix`) in `parse_s3_uri`. The regex is a compile-time constant known to be valid, so the expect marks regex compilation failure as an internal programming error. A non-matching URI is handled separately by returning `None` from the function.
Source
Thrown at quickwit/quickwit-storage/src/object_storage/s3_compatible_storage.rs:249
disable_multipart_upload: self.disable_multipart_upload,
checksum_algorithm: self.checksum_algorithm,
}
}
/// Sets the multipart policy.
///
/// See `MultiPartPolicy`.
#[cfg(feature = "integration-testsuite")]
pub fn set_policy(&mut self, multipart_policy: MultiPartPolicy) {
self.multipart_policy = multipart_policy;
}
}
pub fn parse_s3_uri(uri: &Uri) -> Option<(String, PathBuf)> {
static S3_URI_PTN: LazyLock<Regex> = LazyLock::new(|| {
// s3://bucket/path/to/object
Regex::new(r"s3(\+[^:]+)?://(?P<bucket>[^/]+)(/(?P<prefix>.+))?")
.expect("The regular expression should compile.")
});
let captures = S3_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))
}
/// Maps a [`ChecksumAlgorithm`] onto the AWS SDK's flexible-checksum algorithm.
/// `Md5` returns `None` because the S3 SDK silently no-ops `ChecksumAlgorithm::Md5`;
/// MD5 is instead sent via the legacy `Content-MD5` header, computed client-side.
fn aws_checksum_algorithm(
strategy: quickwit_config::ChecksumAlgorithm,
) -> Option<ChecksumAlgorithm> {View on GitHub (pinned to a39730c5cd)
Solutions
- No runtime action required: the shipped regex is valid.
- When modifying the pattern, run `cargo test -p quickwit-storage` to exercise `LazyLock` initialization.
- Use `map_err` instead of expect for any regex built from runtime input.
Defensive patterns
Strategy: type-guard
Validate before calling
// Callers: handle None as an unsupported S3 URI before proceeding
let (bucket, path) = parse_s3_uri(&uri)
.ok_or_else(|| anyhow::anyhow!("not a valid s3 storage URI: {}", uri))?; Type guard
fn is_s3_uri(uri: &Uri) -> bool {
uri.scheme_str().map(|s| s.starts_with("s3")).unwrap_or(false)
} Try / catch
// The expect panics rather than returning an error; guard by checking the scheme first
if !is_s3_uri(&uri) { bail!("URI is not s3://, cannot build S3CompatibleStorage"); } Prevention
- Validate that object store URIs use the expected scheme before handing them to from_uri.
- Run quickwit-storage unit tests after editing the static S3 regex.
- Use map_err for any regex compiled from non-constant input.
When it happens
Trigger: Only triggered if the static `S3_URI_PTN` regex literal is changed to something invalid (bad group syntax or escape) in a code edit. Supplying a malformed or non-S3 URI at runtime does not panic; it just yields `None` and callers like `from_uri_and_client` report an unsupported URI.
Common situations: Library users never see it. Quickwit contributors hit the pattern when refactoring the S3 URI regex; a typo panics on first `LazyLock` access during tests or startup.
Related errors
- The regular expression should compile.
- The regular expression should compile.
- regular expression should compile
- 1 is always non-zero.
- The prefix should have been prepended to the key before this
AI-assisted analysis of quickwit-oss/quickwit@a39730c5cd (2026-09-08).
Data as JSON: /api/errors/30fc7efe32a49f42.
Report an issue: GitHub.