{"record":{"id":"d92358aa991b0c8d","repo":"influxdata/influxdb","slug":"tried-to-unwrap-a-retry-as-success","errorCode":null,"errorMessage":"tried to unwrap a retry as success","messagePattern":"tried to unwrap a retry as success","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"influxdb3_catalog/src/catalog/versions/v2/update.rs","lineNumber":2069,"sourceCode":"        CatalogBatch::database(\n            txn.time_ns,\n            txn.database_schema.id,\n            Arc::clone(&txn.database_schema.name),\n            ops,\n        )\n    }\n}\n\n#[derive(Debug)]\npub enum Prompt<Success = (), Retry = ()> {\n    Success(Success),\n    Retry(Retry),\n}\n\nimpl<S, R> Prompt<S, R> {\n    pub fn unwrap_success(self) -> S {\n        let Self::Success(s) = self else {\n            panic!(\"tried to unwrap a retry as success\");\n        };\n        s\n    }\n}\n\n#[derive(Debug, Clone, Eq, PartialEq)]\npub(crate) struct Repo<K: Hash + Eq + Copy + Ord, V: CatalogResource> {\n    /// Store for items in the repository\n    pub(crate) repo: IndexMap<K, V>,\n    /// Bi-directional map of identifiers to names in the repository\n    pub(crate) id_name_map: BiHashMap<K, Arc<str>>,\n}\n\nimpl<K: Hash + Eq + Copy + Ord, V: CatalogResource> Repo<K, V> {\n    pub(crate) fn new() -> Self {\n        Self {\n            repo: IndexMap::new(),\n            id_name_map: bimap::BiHashMap::with_hashers(","sourceCodeStart":2051,"sourceCodeEnd":2087,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/influxdb3_catalog/src/catalog/versions/v2/update.rs#L2051-L2087","documentation":"The catalog uses a Prompt<S, R> type that encodes 'apply result' as either Success(S) or Retry(R). unwrap_success() panics if called on a Retry variant. This guards against code assuming an operation will never ask for a retry; calling it on a Retry means the caller mis-modeled the outcome (a retry was requested where only success was legal).","triggerScenarios":"Calling unwrap_success() on a Prompt that holds Retry — typically when an apply/replay step returned Retry (e.g. because a prerequisite state wasn't reached) and the caller unconditionally unwraps.","commonSituations":"Catalog batch application/replay during startup where an earlier batch must be applied first and the code assumed ordered input; custom code extending the catalog applying batches without checking the Prompt variant.","solutions":["Match on the Prompt and handle the Retry variant explicitly instead of unwrapping","Use the appropriate accessor (unwrap_retry / as_retry) after checking the variant","Ensure batches are applied in sequence order so a Retry is never produced on the success-only path","If the retry condition is legitimately impossible in your flow, assert with a contextual message and log the retry payload"],"exampleFix":"// before\nlet schema = prompt.unwrap_success();\n// after\nlet schema = match prompt {\n    Prompt::Success(s) => s,\n    Prompt::Retry(r) => return Err(anyhow!(\"apply deferred: retry required: {r:?}\")),\n};","handlingStrategy":"type-guard","validationCode":"// check the variant before unwrapping\nif matches!(prompt, Prompt::Retry(_)) {\n    return Err(anyhow!(\"apply returned retry; success assumed\"));\n}","typeGuard":"fn is_success<S, R>(p: &Prompt<S, R>) -> bool {\n    matches!(p, Prompt::Success(_))\n}","tryCatchPattern":"match prompt {\n    Prompt::Success(s) => Ok(s),\n    Prompt::Retry(r) => Err(anyhow!(\"unexpected retry: {r:?}\")),\n}","preventionTips":["Always match on Prompt variants; never unwrap unconditionally","Apply catalog batches strictly in sequence order so retries cannot occur","Centralize Prompt handling in one helper with explicit Retry policy","Add tests covering the Retry branch of every apply path"],"tags":["rust","panic","retry","enum"],"backgroundTag":"invalid-state-transition","analyzedSha":"06200ef96ba82c5f6727e5038a83af8e722c6875","analyzedAt":"2026-09-19T12:55:30.003Z","contentChangedAt":"2026-09-19T12:55:30.003Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}