nautechsystems/nautilus_trader · error
Failed to load order events: {e}
Error message
Failed to load order events: {e} What it means
load_order fetches all events for a client_order_id and then assembles an OrderAny from them. When the underlying database query for the order events itself returns an error, the function bails with this message wrapping the query error; note it is distinct from the separate 'Failed to assemble order' error which fires when the query succeeded but event reconstruction failed.
Source
Thrown at crates/infrastructure/src/sql/queries.rs:805
///
/// Returns an error if assembling events or SQL operations fail.
pub async fn load_order(
pool: &PgPool,
client_order_id: &ClientOrderId,
) -> anyhow::Result<Option<OrderAny>> {
let order_events = Self::load_order_events(pool, client_order_id).await;
match order_events {
Ok(order_events) => {
if order_events.is_empty() {
return Ok(None);
}
let order = OrderAny::from_events(order_events).map_err(|e| {
anyhow::anyhow!("Failed to assemble order {client_order_id} from events: {e}")
})?;
Ok(Some(order))
}
Err(e) => anyhow::bail!("Failed to load order events: {e}"),
}
}
/// Loads and assembles all `OrderAny` entries via the provided `pool`.
///
/// # Errors
///
/// Returns an error if loading events or SQL operations fail.
pub async fn load_orders(pool: &PgPool) -> anyhow::Result<Vec<OrderAny>> {
let mut orders: Vec<OrderAny> = Vec::new();
let client_order_ids: Vec<ClientOrderId> = sqlx::query(
r#"
SELECT DISTINCT client_order_id FROM "order_event"
"#,
)
.fetch_all(pool)
.await
.map(|rows| {View on GitHub (pinned to 18893faf8b)
Solutions
- Inspect the wrapped error {e} in the message for the SQLSTATE/driver cause and address it (connectivity, credentials, permissions)
- Run init_postgres / schema initialization first if the order_events table does not exist in the target database
- Verify pool configuration (max connections, timeouts) and database reachability; retry transient connection failures
- Confirm the connection points at the intended database where orders were persisted
Example fix
// before
let order = cache.load_order(&client_order_id)?; // bails if DB unreachable
// after
match cache.load_order(&client_order_id) {
Ok(o) => o,
Err(e) if e.to_string().contains("DatabaseError") => {
tracing::error!("order event query failed: {e}");
return Err(e);
}
Err(e) => return Err(e),
} Defensive patterns
Strategy: retry
Validate before calling
// pre-check table exists before loading
SELECT to_regclass('public.order_events') IS NOT NULL; Try / catch
match cache.load_order(&client_order_id).await {
Ok(Some(o)) => o,
Ok(None) => return Err(anyhow::anyhow!("order not found")),
Err(e) if e.to_string().contains("Failed to load order events") => {
// transient DB issue: backoff and retry
tokio::time::sleep(Duration::from_millis(200)).await;
cache.load_order(&client_order_id).await?
}
Err(e) => return Err(e),
} Prevention
- Initialize the schema (init_postgres) before any load calls
- Configure the PgPool with sane max_size/acquire timeouts and keep the database reachable
- Distinguish this query-failure error from the 'Failed to assemble order' error when triaging logs
When it happens
Trigger: Calling load_order (or load orders via pool) when the SELECT of order_events rows fails: connection pool exhaustion, the database is unreachable, the table does not exist (schema not initialized), or a Postgres error occurs during the query execution.
Common situations: Running queries before init_postgres created the schema tables; network/credential problems between the client and Postgres; connection pool timeouts under load; pointing the client at the wrong database name.
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
- Failed to assign nonce {nonce} to execution intent: {e}
- Failed to insert into position_event table: {e}
- Could not calculate schema dir from current directory path o
- Error executing statement {sql_statement} with error: {e:?}
- Error dropping role {database}: {e:?}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/84316185503da922.
Report an issue: GitHub.