{"record":{"id":"30fc7efe32a49f42","repo":"quickwit-oss/quickwit","slug":"the-regular-expression-should-compile-30fc7e","errorCode":null,"errorMessage":"The regular expression should compile.","messagePattern":"The regular expression should compile\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"quickwit/quickwit-storage/src/object_storage/s3_compatible_storage.rs","lineNumber":249,"sourceCode":"            disable_multipart_upload: self.disable_multipart_upload,\n            checksum_algorithm: self.checksum_algorithm,\n        }\n    }\n\n    /// Sets the multipart policy.\n    ///\n    /// See `MultiPartPolicy`.\n    #[cfg(feature = \"integration-testsuite\")]\n    pub fn set_policy(&mut self, multipart_policy: MultiPartPolicy) {\n        self.multipart_policy = multipart_policy;\n    }\n}\n\npub fn parse_s3_uri(uri: &Uri) -> Option<(String, PathBuf)> {\n    static S3_URI_PTN: LazyLock<Regex> = LazyLock::new(|| {\n        // s3://bucket/path/to/object\n        Regex::new(r\"s3(\\+[^:]+)?://(?P<bucket>[^/]+)(/(?P<prefix>.+))?\")\n            .expect(\"The regular expression should compile.\")\n    });\n\n    let captures = S3_URI_PTN.captures(uri.as_str())?;\n\n    let bucket = captures.name(\"bucket\")?.as_str().to_string();\n    let prefix = captures\n        .name(\"prefix\")\n        .map(|prefix_match| PathBuf::from(prefix_match.as_str()))\n        .unwrap_or_default();\n    Some((bucket, prefix))\n}\n\n/// Maps a [`ChecksumAlgorithm`] onto the AWS SDK's flexible-checksum algorithm.\n/// `Md5` returns `None` because the S3 SDK silently no-ops `ChecksumAlgorithm::Md5`;\n/// MD5 is instead sent via the legacy `Content-MD5` header, computed client-side.\nfn aws_checksum_algorithm(\n    strategy: quickwit_config::ChecksumAlgorithm,\n) -> Option<ChecksumAlgorithm> {","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/quickwit-oss/quickwit/blob/a39730c5cdcd1a4fe798403737ae293999ea21f8/quickwit/quickwit-storage/src/object_storage/s3_compatible_storage.rs#L231-L267","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// Callers: handle None as an unsupported S3 URI before proceeding\nlet (bucket, path) = parse_s3_uri(&uri)\n    .ok_or_else(|| anyhow::anyhow!(\"not a valid s3 storage URI: {}\", uri))?;","typeGuard":"fn is_s3_uri(uri: &Uri) -> bool {\n    uri.scheme_str().map(|s| s.starts_with(\"s3\")).unwrap_or(false)\n}","tryCatchPattern":"// The expect panics rather than returning an error; guard by checking the scheme first\nif !is_s3_uri(&uri) { bail!(\"URI is not s3://, cannot build S3CompatibleStorage\"); }","preventionTips":["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."],"tags":["rust","regex","unreachable-panic","s3"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"a39730c5cdcd1a4fe798403737ae293999ea21f8","analyzedAt":"2026-09-08T13:19:37.784Z","contentChangedAt":"2026-09-08T13:19:37.784Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}