{"record":{"id":"feaa129a0be77095","repo":"nautechsystems/nautilus_trader","slug":"cannot-handle-command-command","errorCode":null,"errorMessage":"Cannot handle command: {command:?}","messagePattern":"Cannot handle command: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/backtest/src/exchange.rs","lineNumber":858,"sourceCode":"                .push(InflightCommand::new(timestamp, counter, command));\n        }\n    }\n\n    fn generate_inflight_command(&mut self, command: &TradingCommand) -> (UnixNanos, u32) {\n        if let Some(latency_model) = &self.latency_model {\n            let ts = match command {\n                TradingCommand::SubmitOrder(_) | TradingCommand::SubmitOrderList(_) => {\n                    command.ts_init() + latency_model.get_insert_latency()\n                }\n                TradingCommand::ModifyOrder(_) | TradingCommand::ModifyOrders(_) => {\n                    command.ts_init() + latency_model.get_update_latency()\n                }\n                TradingCommand::CancelOrder(_)\n                | TradingCommand::CancelOrders(_)\n                | TradingCommand::CancelAllOrders(_) => {\n                    command.ts_init() + latency_model.get_delete_latency()\n                }\n                _ => panic!(\"Cannot handle command: {command:?}\"),\n            };\n\n            let counter = self\n                .inflight_counter\n                .entry(ts)\n                .and_modify(|e| *e += 1)\n                .or_insert(1);\n\n            (ts, *counter)\n        } else {\n            panic!(\"Latency model should be initialized\");\n        }\n    }\n\n    /// Processes a single order book delta.\n    ///\n    /// # Errors\n    ///","sourceCodeStart":840,"sourceCodeEnd":876,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/backtest/src/exchange.rs#L840-L876","documentation":"The backtest exchange's latency-model helper computes submit/modify/cancel latencies for known TradingCommand variants and panics on anything else. The catch-all _ arm means a command kind (e.g. SubmitOrder variants not matched, or future command types) reached code that only models the listed commands. Note the DECLARED/USED metadata references unrelated bench files; the actual panic site is the backtest exchange's inflight-latency calculation.","triggerScenarios":"Calling the latency-computation path in BacktestExchange with a TradingCommand not covered by the explicit Submit/Cancel match arms — typically an unhandled command variant added to the enum or passed through generically.","commonSituations":"Backtesting a strategy that issues a command type the exchange's latency modeler does not handle; core enum extended without updating backtest matching; a new adapter routes a novel command into the backtest engine.","solutions":["Handle the missing TradingCommand variant explicitly in the match (assign appropriate submit/modify latency)","Update the backtest engine to cover all current TradingCommand variants","Check which command your strategy emits and whether it should be mapped to a supported variant","Replace the panic with a fallback/default latency if unknown commands should not abort the backtest"],"exampleFix":"// before\n_ => panic!(\"Cannot handle command: {command:?}\"),\n// after\nTradingCommand::SubmitOrder(_) => command.ts_init() + latency_model.get_submit_latency(),\nTradingCommand::ModifyOrder(_) => command.ts_init() + latency_model.get_modify_latency(),","handlingStrategy":"validation","validationCode":"fn command_has_latency_model(c: &TradingCommand) -> bool {\n    matches!(c, TradingCommand::SubmitOrder(_)\n        | TradingCommand::SubmitOrders(_)\n        | TradingCommand::ModifyOrder(_)\n        | TradingCommand::CancelOrder(_)\n        | TradingCommand::CancelOrders(_)\n        | TradingCommand::CancelAllOrders(_))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the backtest exchange's command match exhaustive (drop the _ arm so the compiler catches new variants)","Update the backtest engine whenever TradingCommand gains variants","Test strategies against the backtest engine with all command types they emit"],"tags":["rust","panic","backtest","latency-model","matching"],"backgroundTag":"unsupported-enum-value","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}