{"record":{"id":"adfe3dda48b03f7e","repo":"quickwit-oss/quickwit","slug":"the-regular-expression-should-compile-adfe3d","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/opendal_storage/google_cloud_storage.rs","lineNumber":101,"sourceCode":"    })?;\n\n    let mut cfg = opendal::services::Gcs::default()\n        .bucket(&bucket_name)\n        .root(&prefix.to_string_lossy());\n\n    if let Some(credential_path) = google_cloud_storage_config.resolve_credential_path() {\n        info!(path=%credential_path, \"fetching google cloud storage credentials from path\");\n        cfg = cfg.credential_path(&credential_path);\n    }\n    let store = OpendalStorage::new_google_cloud_storage(uri.clone(), cfg)?;\n    Ok(store)\n}\n\nfn parse_google_uri(uri: &Uri) -> Option<(String, PathBuf)> {\n    // Ex: gs://bucket/prefix.\n    static URI_PTN: LazyLock<Regex> = LazyLock::new(|| {\n        Regex::new(r\"gs(\\+[^:]+)?://(?P<bucket>[^/]+)(/(?P<prefix>.*))?$\")\n            .expect(\"The regular expression should compile.\")\n    });\n\n    let captures = 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#[cfg(test)]\nmod tests {\n    use std::collections::BTreeMap;\n    use std::path::Path;\n    use std::sync::Arc;\n","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/quickwit-oss/quickwit/blob/a39730c5cdcd1a4fe798403737ae293999ea21f8/quickwit/quickwit-storage/src/opendal_storage/google_cloud_storage.rs#L83-L119","documentation":"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`.","triggerScenarios":"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.","commonSituations":"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.","solutions":["No runtime fix needed: the shipped regex compiles.","After editing the pattern, run `cargo test -p quickwit-storage test_parse_google_uri` to force initialization and detect breakage immediately.","For dynamic regex sources, replace expect with `Regex::new(p).map_err(...)`."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// Callers: treat None as an unsupported GCS URI before use\nlet (bucket, path) = parse_google_uri(&uri)\n    .ok_or_else(|| anyhow::anyhow!(\"not a valid gs:// storage URI: {}\", uri))?;","typeGuard":"fn is_google_uri(uri: &Uri) -> bool {\n    uri.scheme_str().map(|s| s.starts_with(\"gs\")).unwrap_or(false)\n}","tryCatchPattern":"// The expect panics rather than returning an error; guard by checking the scheme first\nif !is_google_uri(&uri) { bail!(\"URI is not gs://, cannot build GoogleCloudStorage\"); }","preventionTips":["Check that configured object store URIs use the gs:// scheme before storage construction.","Exercise test_parse_google_uri after any change to the static regex.","Reserve expect for provably-static regexes only; use map_err elsewhere."],"tags":["rust","regex","unreachable-panic","gcs"],"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-14T11:17:12.474Z"}