{"record":{"id":"3df0f14938d56ba2","repo":"nautechsystems/nautilus_trader","slug":"failed-to-load-pools-e","errorCode":null,"errorMessage":"Failed to load pools: {e}","messagePattern":"Failed to load pools: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":1359,"sourceCode":"\n    /// Loads pool data from the database for the specified chain and DEX.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the database query fails, the connection to the database is lost, or the query parameters are invalid.\n    pub async fn load_pools(\n        &self,\n        chain: SharedChain,\n        dex_id: &str,\n    ) -> anyhow::Result<Vec<PoolRow>> {\n        sqlx::query_as::<_, PoolRow>(AssertSqlSafe(format!(\n            \"SELECT {POOL_ROW_COLUMNS} FROM pool WHERE chain_id = $1 AND dex_name = $2 ORDER BY creation_block ASC\"\n        )))\n        .bind(chain.chain_id as i32)\n        .bind(dex_id)\n        .fetch_all(&self.pool)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to load pools: {e}\"))\n    }\n\n    /// Loads a single pool row by its identifier.\n    ///\n    /// Returns `None` when the pool is not present in the database. Lets per-pool tools load only\n    /// the pool they analyze instead of the whole DEX pool set (see [`load_pools`]).\n    ///\n    /// [`load_pools`]: Self::load_pools\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the database query fails.\n    pub async fn load_pool(\n        &self,\n        chain: SharedChain,\n        dex_id: &str,\n        pool_identifier: &PoolIdentifier,\n    ) -> anyhow::Result<Option<PoolRow>> {","sourceCodeStart":1341,"sourceCodeEnd":1377,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L1341-L1377","documentation":"Wraps a failed SELECT of all pool rows for a given chain and DEX from the `pool` table (ordered by creation_block). The database error is re-thrown as this anyhow error, so only SQL-execution failures (not empty results) trigger it.","triggerScenarios":"Calling `load_pools` when the fetch_all fails: unknown table/column (POOOL_ROW_COLUMNS vs deployed schema mismatch), connection refused/dropped, statement timeout, or invalid dex_id binding.","commonSituations":"Starting the app before migrations ran so the `pool` table is missing; pointing the adapter at the wrong database for the environment; long-running query timing out on very large pool sets.","solutions":["Check the embedded Postgres error for 'relation does not exist' and run `sqlx migrate run`.","Verify the DATABASE_URL points at the intended database for the target chain/dex data.","If timeouts occur on large pool sets, add pagination or index support on (chain_id, dex_name).","Retry on transient connection errors; ensure the pool has healthy connections."],"exampleFix":"// before: load all pools at once\n.fetch_all(&self.pool).await\n.map_err(|e| anyhow::anyhow!(\"Failed to load pools: {e}\"))\n// after: constrain with an index-friendly query and pagination\n// SELECT ... WHERE chain_id = $1 AND dex_name = $2 ORDER BY creation_block ASC LIMIT $3 OFFSET $4;","handlingStrategy":"retry","validationCode":"// verify schema readiness before bulk pool loads\nlet ready: Option<(i64,)> = sqlx::query_as(\n    \"SELECT 1 FROM information_schema.tables WHERE table_name = 'pool'\",\n).fetch_optional(&pool).await?;\nif ready.is_none() { return Err(anyhow!(\"pool table missing; run migrations first\")); }","typeGuard":null,"tryCatchPattern":"let pools = backoff::retry(3, Duration::from_secs(2), || self.load_pools(chain, dex)).await\n    .map_err(|e| anyhow!(\"pool load failed after retries: {e}\"))?;","preventionTips":["Run `sqlx migrate run` as a startup prerequisite.","Add an index on pool (chain_id, dex_name) for large datasets.","Confirm DATABASE_URL points to the correct environment database.","Set a sane statement timeout and paginate instead of loading everything."],"tags":["database","sqlx","postgres","query-failed"],"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"}