{"record":{"id":"34bab034041bbc88","repo":"nautechsystems/nautilus_trader","slug":"failed-to-query-add-currency-to-database-message-h","errorCode":null,"errorMessage":"Failed to query add_currency to database message handler: {e}","messagePattern":"Failed to query add_currency to database message handler: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/cache.rs","lineNumber":916,"sourceCode":"    }\n\n    fn delete_account_event(&self, account_id: &AccountId, event_id: &str) -> anyhow::Result<()> {\n        anyhow::bail!(\n            \"delete_account_event not implemented for PostgreSQL cache adapter: {account_id}, {event_id}\"\n        )\n    }\n\n    fn add(&self, key: String, value: Bytes) -> anyhow::Result<()> {\n        let query = DatabaseQuery::Add(key, value.into());\n        self.tx\n            .send(query)\n            .map_err(|e| anyhow::anyhow!(\"Failed to send query to database message handler: {e}\"))\n    }\n\n    fn add_currency(&self, currency: &Currency) -> anyhow::Result<()> {\n        let query = DatabaseQuery::AddCurrency(*currency);\n        self.tx.send(query).map_err(|e| {\n            anyhow::anyhow!(\"Failed to query add_currency to database message handler: {e}\")\n        })\n    }\n\n    fn add_instrument(&self, instrument: &InstrumentAny) -> anyhow::Result<()> {\n        let query = DatabaseQuery::AddInstrument(instrument.clone());\n        self.tx.send(query).map_err(|e| {\n            anyhow::anyhow!(\"Failed to send query add_instrument to database message handler: {e}\")\n        })\n    }\n\n    fn add_instrument_close(&self, close: &InstrumentClose) -> anyhow::Result<()> {\n        self.tx\n            .send(DatabaseQuery::AddInstrumentClose(*close))\n            .map_err(|e| {\n                anyhow::anyhow!(\n                    \"Failed to send query add_instrument_close to database message handler: {e}\"\n                )\n            })","sourceCodeStart":898,"sourceCodeEnd":934,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/cache.rs#L898-L934","documentation":"Thrown by `add_currency` when the `DatabaseQuery::AddCurrency` message cannot be sent over the mpsc channel to the database message-handler task, which means the receiver has been dropped. The currency is not persisted to the database.","triggerScenarios":"Calling `add_currency` (via `py_add_currency` or `seed_order_event_dependencies`) after the database writer task has exited/been dropped, so `tx.send` returns a SendError.","commonSituations":"Seeding currencies during order-event persistence after the adapter was stopped; a panic in the handler thread; writing during process shutdown.","solutions":["Verify the cache database adapter is running before seeding dependencies.","Inspect receiver task logs for panics that dropped the channel.","Recreate/reconnect the adapter and retry.","Move currency seeding earlier in the workflow, before any shutdown of the writer."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if not cache_db_adapter.is_running:\n    raise RuntimeError(\"Cannot add_currency: adapter not running\")","typeGuard":null,"tryCatchPattern":"try:\n    cache.add_currency(currency)\nexcept RuntimeError as e:\n    logger.error(\"Currency persistence failed (writer stopped): %s\", e)","preventionTips":["Seed currencies early, while the adapter is definitely connected","Avoid dependency seeding during shutdown","Alert on writer-task panics","Retry after reconnecting the adapter"],"tags":["database","channel","currency","shutdown"],"backgroundTag":"database-write-failed","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"}