nautechsystems/nautilus_trader · error · anyhow::Error
Failed to load pool {pool_identifier}: {e}
Error message
Failed to load pool {pool_identifier}: {e} What it means
Wraps a failed SELECT of a single pool row by identifier (fetch_optional). Only an SQL-execution failure raises this error; a missing row legitimately returns None and does not error. The pool identifier is interpolated into the message for quick diagnosis.
Source
Thrown at crates/adapters/blockchain/src/cache/database.rs:1386
///
/// # Errors
///
/// Returns an error if the database query fails.
pub async fn load_pool(
&self,
chain: SharedChain,
dex_id: &str,
pool_identifier: &PoolIdentifier,
) -> anyhow::Result<Option<PoolRow>> {
sqlx::query_as::<_, PoolRow>(AssertSqlSafe(format!(
"SELECT {POOL_ROW_COLUMNS} FROM pool WHERE chain_id = $1 AND dex_name = $2 AND pool_identifier = $3"
)))
.bind(chain.chain_id as i32)
.bind(dex_id)
.bind(pool_identifier.as_ref())
.fetch_optional(&self.pool)
.await
.map_err(|e| anyhow::anyhow!("Failed to load pool {pool_identifier}: {e}"))
}
/// Toggles performance optimization settings for sync operations.
///
/// When enabled (true), applies settings for maximum write performance:
/// - `synchronous_commit` = OFF
/// - `work_mem` increased for bulk operations
///
/// When disabled (false), restores default safe settings:
/// - `synchronous_commit` = ON (data safety)
/// - `work_mem` back to default
///
/// # Errors
///
/// Returns an error if the database operations fail.
pub async fn toggle_perf_sync_settings(&self, enable: bool) -> anyhow::Result<()> {
if enable {
log::debug!("Enabling performance sync settings for bulk operations");View on GitHub (pinned to 18893faf8b)
Solutions
- Read the underlying `{e}`; for 'relation does not exist' run pending migrations.
- Treat None results as expected — only act when the embedded SQL error indicates a real failure.
- Confirm the identifier format matches the column's stored format (e.g. lowercase address).
- Check database reachability and retry transient connection errors.
Example fix
// before: error conflated with not-found handling
let row = self.load_pool(chain, dex_id, id).await?;
// after: handle None explicitly, error only on real failures
match self.load_pool(chain, dex_id, id).await {
Ok(Some(pool)) => analyze(pool),
Ok(None) => log::warn!("pool {id} not found"),
Err(e) => return Err(e),
} Defensive patterns
Strategy: try-catch
Validate before calling
// validate the identifier shape before querying
let is_valid_id = |id: &str| !id.is_empty() && id.len() <= 64;
if !is_valid_id(pool_identifier.as_ref()) { return Err(anyhow!("invalid pool identifier")); } Try / catch
match self.load_pool(chain, dex, id).await {
Ok(Some(pool)) => Ok(Some(pool)),
Ok(None) => Ok(None), // not-found is not an error
Err(e) => Err(anyhow!("pool lookup for {id} failed: {e}")),
} Prevention
- Treat None as a normal outcome — do not conflate with errors.
- Store and query identifiers in a canonical case (lowercase addresses).
- Ensure migrations are applied before per-pool analysis tools run.
- Retry once on transient connection errors.
When it happens
Trigger: Calling the per-pool loader (database.rs, load single pool by id) when the query itself fails: missing table/column, connection drop, statement timeout, or an identifier string that cannot bind to the column type.
Common situations: Tooling that loads one pool for analysis running while migrations are incomplete; DB connectivity blips during per-pool analysis loops; schema changes renaming a column used in POOL_ROW_COLUMNS.
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 load tokens: {e}
- Failed to load pools: {e}
- Failed to seed chain table: {e}
- Failed to call create_block_partition for chain {}: {e}
- Failed to call create_token_partition for chain {}: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/27ba5bf124b2d2b4.
Report an issue: GitHub.