{"record":{"id":"bfd138854a72eeb2","repo":"nautechsystems/nautilus_trader","slug":"python-on-fault-failed-e","errorCode":null,"errorMessage":"Python on_fault failed: {e}","messagePattern":"Python on_fault failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/python/actor.rs","lineNumber":1050,"sourceCode":"\n    fn on_reset(&mut self) -> anyhow::Result<()> {\n        self.dispatch_on_reset()\n            .map_err(|e| anyhow::anyhow!(\"Python on_reset failed: {e}\"))\n    }\n\n    fn on_dispose(&mut self) -> anyhow::Result<()> {\n        self.dispatch_on_dispose()\n            .map_err(|e| anyhow::anyhow!(\"Python on_dispose failed: {e}\"))\n    }\n\n    fn on_degrade(&mut self) -> anyhow::Result<()> {\n        self.dispatch_on_degrade()\n            .map_err(|e| anyhow::anyhow!(\"Python on_degrade failed: {e}\"))\n    }\n\n    fn on_fault(&mut self) -> anyhow::Result<()> {\n        self.dispatch_on_fault()\n            .map_err(|e| anyhow::anyhow!(\"Python on_fault failed: {e}\"))\n    }\n\n    fn on_save(&self) -> anyhow::Result<IndexMap<String, Vec<u8>>> {\n        self.dispatch_on_save()\n            .map_err(|e| anyhow::anyhow!(\"Python on_save failed: {e}\"))\n    }\n\n    fn on_load(&mut self, state: IndexMap<String, Vec<u8>>) -> anyhow::Result<()> {\n        self.dispatch_on_load(&state)\n            .map_err(|e| anyhow::anyhow!(\"Python on_load failed: {e}\"))\n    }\n\n    fn on_time_event(&mut self, event: &TimeEvent) -> anyhow::Result<()> {\n        self.dispatch_on_time_event(event.clone())\n            .map_err(|e| anyhow::anyhow!(\"Python on_time_event failed: {e}\"))\n    }\n\n    #[allow(unused_variables)]","sourceCodeStart":1032,"sourceCodeEnd":1068,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/python/actor.rs#L1032-L1068","documentation":"Raised by the Rust `DataActor` bridge when the Python actor's `on_fault()` callback raises an exception. `dispatch_on_fault()` forwards to Python and the exception is rewrapped with this message. on_fault handles the transition into a faulted (non-recoverable) state.","triggerScenarios":"Any exception in the user's Python `on_fault`: emergency flattening positions and hitting an API error, logging to an unavailable sink, or dereferencing attributes that are None during the fault path.","commonSituations":"Fault handling in live trading where the fault handler itself is buggy, masking the original fault; on_fault trying to send notifications through a client that is down.","solutions":["Read the Python traceback in the error to pinpoint the failure inside on_fault.","Keep on_fault minimal and fully guarded in try/except so fault handling never itself raises.","Verify emergency actions (position flattening, notifications) handle unavailable dependencies gracefully.","Trigger a fault deliberately in staging to validate the handler."],"exampleFix":"// before (Python)\ndef on_fault(self):\n    self.close_all_positions()\n\n// after\ndef on_fault(self):\n    try:\n        self.close_all_positions()\n    except Exception as e:\n        self.log.error(f\"emergency flatten failed: {e}\")","handlingStrategy":"try-catch","validationCode":"# fault-path readiness check\nassert callable(getattr(self, 'close_all_positions', None)), 'emergency handler missing'","typeGuard":"def fault_ready(actor):\n    return callable(getattr(actor, 'on_fault', None))","tryCatchPattern":"def on_fault(self):\n    try:\n        ...  # emergency actions\n    except Exception as e:\n        self.log.critical(f\"fault handler failed: {e}\")","preventionTips":["Keep on_fault minimal and every statement guarded — a raising fault handler masks the root cause.","Do not rely on external services (notification clients) inside on_fault; use local logging fallback.","Deliberately trigger faults in staging to validate the handler.","Alert on fault-handler exceptions so they are never silently ignored."],"tags":["python","actor-lifecycle","callback-exception","rust-bridge"],"backgroundTag":"python-callback-raised-exception","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"}