{"record":{"id":"9c5a82fed8b87e6a","repo":"nautechsystems/nautilus_trader","slug":"cannot-send-order-event-sender-not-initialized","errorCode":null,"errorMessage":"Cannot send order event: sender not initialized","messagePattern":"Cannot send order event: sender not initialized","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/live/src/execution/emitter.rs","lineNumber":441,"sourceCode":"    }\n\n    /// Emits an order event.\n    pub fn send_order_event(&self, event: OrderEventAny) {\n        if let Err(e) = self.try_send_order_event(event) {\n            log::warn!(\"{e}\");\n        }\n    }\n\n    /// Emits an order event and returns any channel error to the caller.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the sender is uninitialized or its receiver is closed.\n    pub fn try_send_order_event(&self, event: OrderEventAny) -> anyhow::Result<()> {\n        let sender = self.sender.load();\n        let sender = sender\n            .as_ref()\n            .ok_or_else(|| anyhow::anyhow!(\"Cannot send order event: sender not initialized\"))?;\n        sender\n            .send(ExecutionEvent::Order(event))\n            .map_err(|e| anyhow::anyhow!(\"Failed to send order event: {e}\"))\n    }\n\n    /// Emits a batch of order submitted events as a single channel message.\n    pub fn send_order_submitted_batch(&self, batch: OrderSubmittedBatch) {\n        let sender = self.sender.load();\n        if let Some(sender) = sender.as_ref() {\n            if let Err(e) = sender.send(ExecutionEvent::OrderSubmittedBatch(batch)) {\n                log::warn!(\"Failed to send order submitted batch: {e}\");\n            }\n        } else {\n            log::warn!(\"Cannot send order submitted batch: sender not initialized\");\n        }\n    }\n\n    /// Emits a batch of order accepted events as a single channel message.","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/live/src/execution/emitter.rs#L423-L459","documentation":"ExecutionEmitter lazily holds an Option-like sender (`self.sender.load()`), which is only populated once the emitter is started/initialized. This error is raised by try_send_order_event when that sender slot is still None, so an order event cannot be routed to the execution event stream. It signals a lifecycle bug: the emitter is being used before initialization.","triggerScenarios":"Calling try_send_order_event (directly or via send_order_event, send_reverted_order, commit_post_reconnect_mass_status, or complete_finalized_swap) before the emitter's sender has been initialized (e.g. before the execution engine/manager start sequence wires the channel).","commonSituations":"Bots that replay or reconcile orders immediately after connecting to a venue but before the live execution engine finishes startup; reconnect/recovery paths (mass status commit, swap finalization) racing the emitter initialization; custom adapters invoking the emitter out of order.","solutions":["Ensure the ExecutionEmitter is initialized (its `initialize`/start path has run) before emitting any order events.","Check startup ordering so that reconnect recovery (commit_post_reconnect_mass_status) runs only after the execution engine and emitter are fully wired.","Guard calls with a readiness check on the emitter and log/skip or queue events until initialized.","If this occurs unexpectedly, report/inspect: the sender should always be set once the live node is running."],"exampleFix":"// before\nemitter.send_order_event(event); // panics-ish error if not initialized\n// after\nif emitter.is_initialized() {\n    if let Err(e) = emitter.try_send_order_event(event) { log::error!(\"{e}\"); }\n} else {\n    log::warn!(\"emitter not initialized; dropping/deferring order event\");\n}","handlingStrategy":"try-catch","validationCode":"if !emitter.is_initialized() { log::warn!(\"emitter not ready\"); return; }","typeGuard":"fn emitter_ready(emitter: &ExecutionEmitter) -> bool { emitter.is_initialized() }","tryCatchPattern":"match emitter.try_send_order_event(event) { Err(e) if e.to_string().contains(\"sender not initialized\") => log::warn!(\"emitter not initialized: {e}\"), Err(e) => log::error!(\"order event send failed: {e}\"), Ok(()) => {} }","preventionTips":["Always start the live execution engine before any adapter emits events","Gate reconnect/recovery handlers on engine readiness","Add startup-order integration tests for adapters"],"tags":["rust","lifecycle","execution","channel"],"backgroundTag":"invalid-state-transition","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"}