nautechsystems/nautilus_trader · error
Failed to load account events: {e}
Error message
Failed to load account events: {e} What it means
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.
Source
Thrown at crates/infrastructure/src/sql/queries.rs:1201
/// # Errors
///
/// Returns an error if assembling events or SQL operations fail.
pub async fn load_account(
pool: &PgPool,
account_id: &AccountId,
) -> anyhow::Result<Option<AccountAny>> {
let account_events = Self::load_account_events(pool, account_id).await;
match account_events {
Ok(account_events) => {
if account_events.is_empty() {
return Ok(None);
}
let account = AccountAny::from_events(&account_events).map_err(|e| {
anyhow::anyhow!("Failed to assemble account {account_id} from events: {e}")
})?;
Ok(Some(account))
}
Err(e) => anyhow::bail!("Failed to load account events: {e}"),
}
}
/// Loads and assembles all `AccountAny` entries via the provided `pool`.
///
/// # Errors
///
/// Returns an error if loading events or SQL operations fail.
pub async fn load_accounts(pool: &PgPool) -> anyhow::Result<Vec<AccountAny>> {
let mut accounts: Vec<AccountAny> = Vec::new();
let account_ids: Vec<AccountId> = sqlx::query(
r#"
SELECT DISTINCT account_id FROM "account_event"
"#,
)
.fetch_all(pool)
.await
.map(|rows| {View on GitHub (pinned to 18893faf8b)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
// before load: verify DB reachability and schema
sqlx::query("SELECT 1 FROM account_events LIMIT 1").execute(&pool).await?; Try / catch
match AccountQueries::load_account(&pool, account_id).await {
Ok(Some(account)) => account,
Ok(None) => return /* not cached */,
Err(e) => {
log::error!("account load failed: {e:#}");
/* reconnect pool / run migrations / retry with backoff */
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- Implement FromRow for FuturesSpread
- Implement FromRow for OptionSpread
- Failed to validate nonce recovery ownership: {e}
- Execution transaction {transaction_hash} was not found for s
- Failed to load from execution_transaction table: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/6c954bda4a4124fe.
Report an issue: GitHub.