{"record":{"id":"27ba5bf124b2d2b4","repo":"nautechsystems/nautilus_trader","slug":"failed-to-load-pool-pool-identifier-e","errorCode":null,"errorMessage":"Failed to load pool {pool_identifier}: {e}","messagePattern":"Failed to load pool (.+?): (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":1386,"sourceCode":"    ///\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>> {\n        sqlx::query_as::<_, PoolRow>(AssertSqlSafe(format!(\n            \"SELECT {POOL_ROW_COLUMNS} FROM pool WHERE chain_id = $1 AND dex_name = $2 AND pool_identifier = $3\"\n        )))\n        .bind(chain.chain_id as i32)\n        .bind(dex_id)\n        .bind(pool_identifier.as_ref())\n        .fetch_optional(&self.pool)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to load pool {pool_identifier}: {e}\"))\n    }\n\n    /// Toggles performance optimization settings for sync operations.\n    ///\n    /// When enabled (true), applies settings for maximum write performance:\n    /// - `synchronous_commit` = OFF\n    /// - `work_mem` increased for bulk operations\n    ///\n    /// When disabled (false), restores default safe settings:\n    /// - `synchronous_commit` = ON (data safety)\n    /// - `work_mem` back to default\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the database operations fail.\n    pub async fn toggle_perf_sync_settings(&self, enable: bool) -> anyhow::Result<()> {\n        if enable {\n            log::debug!(\"Enabling performance sync settings for bulk operations\");","sourceCodeStart":1368,"sourceCodeEnd":1404,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L1368-L1404","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: error conflated with not-found handling\nlet row = self.load_pool(chain, dex_id, id).await?;\n// after: handle None explicitly, error only on real failures\nmatch self.load_pool(chain, dex_id, id).await {\n    Ok(Some(pool)) => analyze(pool),\n    Ok(None) => log::warn!(\"pool {id} not found\"),\n    Err(e) => return Err(e),\n}","handlingStrategy":"try-catch","validationCode":"// validate the identifier shape before querying\nlet is_valid_id = |id: &str| !id.is_empty() && id.len() <= 64;\nif !is_valid_id(pool_identifier.as_ref()) { return Err(anyhow!(\"invalid pool identifier\")); }","typeGuard":null,"tryCatchPattern":"match self.load_pool(chain, dex, id).await {\n    Ok(Some(pool)) => Ok(Some(pool)),\n    Ok(None) => Ok(None), // not-found is not an error\n    Err(e) => Err(anyhow!(\"pool lookup for {id} failed: {e}\")),\n}","preventionTips":["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."],"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"}