{"record":{"id":"68286b86ec70ee49","repo":"nautechsystems/nautilus_trader","slug":"error-loading-cache-data-e-68286b","errorCode":null,"errorMessage":"Error loading cache data: {e}","messagePattern":"Error loading cache data: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/cache.rs","lineNumber":510,"sourceCode":"\n        Ok(rx.recv()?)\n    }\n\n    async fn load_all(&self) -> anyhow::Result<CacheMap> {\n        let currencies = self.load_currencies().await?;\n        for currency in currencies.values() {\n            Currency::register(*currency, false)?;\n        }\n\n        let (instruments, instrument_closes, synthetics, accounts, orders, positions) = try_join!(\n            self.load_instruments(),\n            self.load_instrument_closes(),\n            self.load_synthetics(),\n            self.load_accounts(),\n            self.load_orders(),\n            self.load_positions()\n        )\n        .map_err(|e| anyhow::anyhow!(\"Error loading cache data: {e}\"))?;\n\n        // For now, we don't load greeks and yield curves from the database\n        // This will be implemented in the future\n        let greeks = AHashMap::new();\n        let yield_curves = AHashMap::new();\n\n        Ok(CacheMap {\n            currencies,\n            instruments,\n            instrument_closes,\n            synthetics,\n            accounts,\n            orders,\n            positions,\n            greeks,\n            yield_curves,\n        })\n    }","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/cache.rs#L492-L528","documentation":"Error wrapping any failure from the individual cache `load_*` queries (instruments, synthetics, accounts, orders, positions) that run during `load_all`, the bulk restore of cache state from the SQL database. It indicates the cache could not be fully populated from the database, so in-memory state is incomplete or empty. The original database error text is embedded in `{e}`.","triggerScenarios":"Calling `load_all` (e.g. via cache database adapter startup) when the database is unreachable, credentials are wrong, the schema/tables are missing or stale, or one of load_instrument_closes/load_synthetics/load_accounts/load_orders/load_positions returns a query error.","commonSituations":"Postgres/MySQL container not started; wrong connection URL in the cache database config; migration not applied so expected tables don't exist; corrupted or incompatible rows from an older schema version.","solutions":["Read the inner `{e}` message to identify the actual database failure and fix that root cause.","Verify the database is running and reachable (`psql`/`mysql` connect with the same URL).","Confirm the connection config (host, port, user, password, database name) matches the running instance.","Apply/verify the schema migrations so all expected tables exist.","If the error occurs during non-critical startup, make load_all fallible in your setup and handle the Err instead of unwrapping."],"exampleFix":"// before\nlet cache_data = join_all_futures(...).map_err(|e| anyhow::anyhow!(\"Error loading cache data: {e}\"))?;\n// after\nmatch load_all() {\n    Ok(data) => install(data),\n    Err(e) => { tracing::error!(\"Cache load failed, starting with empty cache: {e:#}\"); Default::default() }\n}","handlingStrategy":"try-catch","validationCode":"# Python: check DB connectivity before load_all\nimport psycopg\ntry:\n    with psycopg.connect(conn_string, connect_timeout=5) as conn:\n        conn.execute(\"SELECT 1 FROM instrument\")\nexcept Exception as e:\n    raise RuntimeError(f\"Cache database unavailable before load_all: {e}\")","typeGuard":null,"tryCatchPattern":"try:\n    cache_db.load_all()\nexcept Exception as e:\n    logger.error(\"Cache load from database failed: %s\", e)\n    # decide: abort startup or continue with empty cache\n    raise","preventionTips":["Run a connectivity/schema smoke query before starting the cache database adapter","Keep migrations applied as part of deployment","Centralize connection config and validate it at startup","Log the inner error chain (`{e:#}` style) to see the real cause"],"tags":["database","cache","sql","startup"],"backgroundTag":"database-query-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"}