{"record":{"id":"3395617054ae8566","repo":"nautechsystems/nautilus_trader","slug":"guarded-above","errorCode":null,"errorMessage":"guarded above","messagePattern":"guarded above","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/derive/src/execution.rs","lineNumber":776,"sourceCode":"                        .get_trigger_orders(&DeriveGetTriggerOrdersParams::new(subaccount_id))\n                        .await?\n                        .orders;\n\n                    match trigger_orders\n                        .into_iter()\n                        .find(|o| o.order_id.as_str() == venue_order_id.as_str())\n                    {\n                        Some(order) => Some(order),\n                        None => return Err(e.into()),\n                    }\n                }\n            }\n        } else {\n            // Derive has no by-label lookup endpoint; scan open orders first,\n            // then trigger orders, then fall through to paginated history so\n            // terminal orders resolve for reconcilers that only carry the\n            // client_order_id.\n            let label = cmd.client_order_id.expect(\"guarded above\");\n            let open_orders = self\n                .http_client\n                .get_open_orders(&DeriveGetOpenOrdersParams::new(subaccount_id))\n                .await?\n                .orders;\n            let mut found = open_orders.into_iter().find(|o| o.label == label.as_str());\n\n            if found.is_none() {\n                let trigger_orders = self\n                    .http_client\n                    .get_trigger_orders(&DeriveGetTriggerOrdersParams::new(subaccount_id))\n                    .await?\n                    .orders;\n                found = trigger_orders\n                    .into_iter()\n                    .find(|o| o.label == label.as_str());\n            }\n","sourceCodeStart":758,"sourceCodeEnd":794,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/derive/src/execution.rs#L758-L794","documentation":"In `generate_order_status_report`, when a status command carries only a `client_order_id`, the adapter maps it to a Derive order label. Derive has no by-label lookup endpoint, so the code scans open orders and trigger orders. The `expect(\"guarded above\")` asserts that an earlier match arm guaranteed `client_order_id` is Some by the time this branch runs; the panic indicates the guard and this branch have diverged.","triggerScenarios":"Calling `generate_order_status_report` where control flow reaches the label-scan branch with `cmd.client_order_id == None` — i.e. the upstream guard checked a different field or a new command shape bypassed the guard (e.g. query by venue_order_id-only routed here incorrectly).","commonSituations":"Seen after refactoring the report-generation match arms, or when a reconciler sends a status request whose command variant slipped past the intended guard (order_id set instead of client_order_id).","solutions":["Fix the guard earlier in the function so it checks exactly the same condition (client_order_id is Some) as this branch.","Return a proper error (e.g. \"order status requires client_order_id or venue_order_id\") instead of panicking when neither ID is present.","Log the full command when the expect would fire to identify which request shape bypassed the guard.","Add a unit test covering status queries with only venue_order_id, only client_order_id, and neither."],"exampleFix":"// before\nlet label = cmd.client_order_id.expect(\"guarded above\");\n// after\nlet Some(label) = cmd.client_order_id.as_ref() else {\n    return Err(derive_error(\"order status requires a client_order_id\"));\n};","handlingStrategy":"validation","validationCode":"let Some(label) = cmd.client_order_id.as_ref() else {\n    return Err(/* order status requires client_order_id or venue_order_id */);\n};","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the guard and the branch conditions identical; prefer early-return with an error over expect","Always attach a client_order_id to status queries that rely on label lookup","Test status reports for all ID combinations (client_order_id only, venue_order_id only, neither)"],"tags":["rust","panic","rest","order-status","internal-invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}