{"record":{"id":"6c954bda4a4124fe","repo":"nautechsystems/nautilus_trader","slug":"failed-to-load-account-events-e","errorCode":null,"errorMessage":"Failed to load account events: {e}","messagePattern":"Failed to load account events: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/queries.rs","lineNumber":1201,"sourceCode":"    /// # Errors\n    ///\n    /// Returns an error if assembling events or SQL operations fail.\n    pub async fn load_account(\n        pool: &PgPool,\n        account_id: &AccountId,\n    ) -> anyhow::Result<Option<AccountAny>> {\n        let account_events = Self::load_account_events(pool, account_id).await;\n        match account_events {\n            Ok(account_events) => {\n                if account_events.is_empty() {\n                    return Ok(None);\n                }\n                let account = AccountAny::from_events(&account_events).map_err(|e| {\n                    anyhow::anyhow!(\"Failed to assemble account {account_id} from events: {e}\")\n                })?;\n                Ok(Some(account))\n            }\n            Err(e) => anyhow::bail!(\"Failed to load account events: {e}\"),\n        }\n    }\n\n    /// Loads and assembles all `AccountAny` entries via the provided `pool`.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if loading events or SQL operations fail.\n    pub async fn load_accounts(pool: &PgPool) -> anyhow::Result<Vec<AccountAny>> {\n        let mut accounts: Vec<AccountAny> = Vec::new();\n        let account_ids: Vec<AccountId> = sqlx::query(\n            r#\"\n            SELECT DISTINCT account_id FROM \"account_event\"\n        \"#,\n        )\n        .fetch_all(pool)\n        .await\n        .map(|rows| {","sourceCodeStart":1183,"sourceCodeEnd":1219,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/queries.rs#L1183-L1219","documentation":"Thrown by `load_account` when the SQL query that fetches the account's persisted event rows fails (the `Err(e)` arm of the query result). The underlying sqlx/database error is wrapped with context naming the operation; the account cannot be loaded from the cache database.","triggerScenarios":"Calling `AccountQueries::load_account(pool, account_id)` when the SELECT of account events fails: connection failure, wrong table schema (migrations not applied), permission denied, or the pool being closed/unreachable.","commonSituations":"Postgres not running or wrong connection string; database schema out of date after upgrading nautilus (missing migrations); the DB user lacking SELECT privileges; network/firewall issues in containerized deployments.","solutions":["Read the wrapped `e` in the error message to identify the underlying sqlx/Postgres error and fix that cause first.","Verify the connection string, network reachability, and that Postgres is running.","Run the database migrations so the expected tables/schema exist.","Grant the DB user SELECT permission on the account events tables."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before load: verify DB reachability and schema\nsqlx::query(\"SELECT 1 FROM account_events LIMIT 1\").execute(&pool).await?;","typeGuard":null,"tryCatchPattern":"match AccountQueries::load_account(&pool, account_id).await {\n    Ok(Some(account)) => account,\n    Ok(None) => return /* not cached */,\n    Err(e) => {\n        log::error!(\"account load failed: {e:#}\");\n        /* reconnect pool / run migrations / retry with backoff */\n    }\n}","preventionTips":["Run database migrations after every nautilus upgrade so schema matches.","Health-check the Postgres connection (SELECT 1) before node start.","Grant the DB user the required SELECT privileges.","Wrap wrapped-error chains with `{e:#}` logging to expose the root cause."],"tags":["database","network","sqlx","rust"],"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-14T05:17:10.506Z"}