{"record":{"id":"384e46c3a35ea896","repo":"nautechsystems/nautilus_trader","slug":"python-simulationmodule-process-failed-e","errorCode":null,"errorMessage":"Python SimulationModule.process failed: {e}","messagePattern":"Python SimulationModule\\.process failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/backtest/src/python/modules.rs","lineNumber":296,"sourceCode":"\n    fn process(\n        &self,\n        ts_now: nautilus_core::UnixNanos,\n        ctx: &ExchangeContext,\n    ) -> anyhow::Result<SimulationModuleResult> {\n        Python::attach(|py| -> anyhow::Result<SimulationModuleResult> {\n            let context = Py::new(py, PySimulationModuleContext::from_exchange(ctx))?;\n            let adjustments = self\n                .obj\n                .bind(py)\n                .call_method1(\"process\", (ts_now.as_u64(), context))?\n                .extract::<Option<Vec<Money>>>()?;\n            Ok(adjustments.map_or(\n                SimulationModuleResult::NotReady,\n                SimulationModuleResult::Completed,\n            ))\n        })\n        .map_err(|e| anyhow::anyhow!(\"Python SimulationModule.process failed: {e}\"))\n    }\n\n    fn acknowledge(&self, outcomes: &[AccountAdjustmentOutcome]) -> anyhow::Result<()> {\n        Python::attach(|py| -> anyhow::Result<()> {\n            let outcomes = outcomes\n                .iter()\n                .map(PyAccountAdjustmentOutcome::from)\n                .collect::<Vec<_>>();\n            self.obj.bind(py).call_method1(\"acknowledge\", (outcomes,))?;\n            Ok(())\n        })\n        .map_err(|e| anyhow::anyhow!(\"Python SimulationModule.acknowledge failed: {e}\"))\n    }\n\n    fn log_diagnostics(&self) -> anyhow::Result<()> {\n        Python::attach(|py| -> anyhow::Result<()> {\n            self.obj.bind(py).call_method0(\"log_diagnostics\")?;\n            Ok(())","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/backtest/src/python/modules.rs#L278-L314","documentation":"FFI boundary error in the Python SimulationModule wrapper: the module's Python process() callback raised an exception or returned a bad value; the Python error is embedded in the message and the simulation step fails.","triggerScenarios":"The Python object's process(ts_now, data, ...) raises during exchange processing (e.g. arithmetic on None, missing account state, exceptions in custom liquidity/fill logic).","commonSituations":"Custom fee/latency/fill modules hitting unhandled market states (first tick, empty book, halted instrument); division by zero in slippage calculations.","solutions":["Inspect the embedded Python traceback and fix the exception in the module's process method.","Handle edge cases: empty/None inputs, first-tick state, zero quantities.","Reproduce with a minimal data slice (single tick/bar) to debug quickly."],"exampleFix":"# before\ndef process(self, ts_now, data):\n    return self.book[data.instrument_id].best_bid()  # KeyError\n# after\ndef process(self, ts_now, data):\n    book = self.book.get(data.instrument_id)\n    return book.best_bid() if book else None","handlingStrategy":"try-catch","validationCode":"module.process(0, sample_data, sample_ctx)  # smoke-test edge inputs before the run\n","typeGuard":null,"tryCatchPattern":"class SafeModule(SimulationModule):\n    def process(self, ts_now, data, ctx):\n        try:\n            return self._process(ts_now, data, ctx)\n        except Exception:\n            logging.exception(\"SimulationModule.process failed at ts=%s\", ts_now)\n            raise\n","preventionTips":["Guard against empty books, zero quantities, and first-tick states in process().","Reproduce failures with a minimal single-tick data slice.","Keep per-instrument state in dicts accessed via .get() with defaults."],"tags":["python","backtest","simulation-module","callback"],"backgroundTag":"upstream-api-error","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"}