nautechsystems/nautilus_trader · error

Error loading cache data: {e}

Error message

Error loading cache data: {e}

What it means

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}`.

Source

Thrown at crates/infrastructure/src/sql/cache.rs:510

        Ok(rx.recv()?)
    }

    async fn load_all(&self) -> anyhow::Result<CacheMap> {
        let currencies = self.load_currencies().await?;
        for currency in currencies.values() {
            Currency::register(*currency, false)?;
        }

        let (instruments, instrument_closes, synthetics, accounts, orders, positions) = try_join!(
            self.load_instruments(),
            self.load_instrument_closes(),
            self.load_synthetics(),
            self.load_accounts(),
            self.load_orders(),
            self.load_positions()
        )
        .map_err(|e| anyhow::anyhow!("Error loading cache data: {e}"))?;

        // For now, we don't load greeks and yield curves from the database
        // This will be implemented in the future
        let greeks = AHashMap::new();
        let yield_curves = AHashMap::new();

        Ok(CacheMap {
            currencies,
            instruments,
            instrument_closes,
            synthetics,
            accounts,
            orders,
            positions,
            greeks,
            yield_curves,
        })
    }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Read the inner `{e}` message to identify the actual database failure and fix that root cause.
  2. Verify the database is running and reachable (`psql`/`mysql` connect with the same URL).
  3. Confirm the connection config (host, port, user, password, database name) matches the running instance.
  4. Apply/verify the schema migrations so all expected tables exist.
  5. If the error occurs during non-critical startup, make load_all fallible in your setup and handle the Err instead of unwrapping.

Example fix

// before
let cache_data = join_all_futures(...).map_err(|e| anyhow::anyhow!("Error loading cache data: {e}"))?;
// after
match load_all() {
    Ok(data) => install(data),
    Err(e) => { tracing::error!("Cache load failed, starting with empty cache: {e:#}"); Default::default() }
}
Defensive patterns

Strategy: try-catch

Validate before calling

# Python: check DB connectivity before load_all
import psycopg
try:
    with psycopg.connect(conn_string, connect_timeout=5) as conn:
        conn.execute("SELECT 1 FROM instrument")
except Exception as e:
    raise RuntimeError(f"Cache database unavailable before load_all: {e}")

Try / catch

try:
    cache_db.load_all()
except Exception as e:
    logger.error("Cache load from database failed: %s", e)
    # decide: abort startup or continue with empty cache
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/68286b86ec70ee49. Report an issue: GitHub.