{"record":{"id":"a13897d8c912c9af","repo":"nautechsystems/nautilus_trader","slug":"dex-dex-id-has-not-been-registered","errorCode":null,"errorMessage":"DEX {dex_id:?} has not been registered","messagePattern":"DEX (.+?) has not been registered","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/mod.rs","lineNumber":361,"sourceCode":"            self.invalid_tokens.extend(invalid_tokens);\n        }\n        Ok(())\n    }\n\n    /// Loads DEX exchange pools from the database into the in-memory cache.\n    ///\n    /// Returns the loaded pools.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the DEX has not been registered or if database operations fail.\n    pub async fn load_pools(&mut self, dex_id: &DexType) -> anyhow::Result<Vec<Pool>> {\n        let mut loaded_pools = Vec::new();\n\n        if let Some(database) = &self.database {\n            let dex = self\n                .get_dex(dex_id)\n                .ok_or_else(|| anyhow::anyhow!(\"DEX {dex_id:?} has not been registered\"))?;\n            let pool_rows = database\n                .load_pools(self.chain.clone(), &dex_id.to_string())\n                .await?;\n            log::debug!(\n                \"Loading {} pools for DEX {} from cache database\",\n                pool_rows.len(),\n                dex_id,\n            );\n\n            for pool_row in pool_rows {\n                if let Some(pool) = self.build_pool_from_row(&pool_row, &dex) {\n                    loaded_pools.push(pool.clone());\n                    self.pools.insert(pool.pool_identifier, Arc::new(pool));\n                }\n            }\n        }\n        Ok(loaded_pools)\n    }","sourceCodeStart":343,"sourceCodeEnd":379,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/mod.rs#L343-L379","documentation":"load_pools loads persisted pools for a given DEX, but first requires that the DEX has been registered in the cache's in-memory dex registry (via get_dex). This error is thrown when load_pools is called with a DexType that was never registered, so the cache cannot resolve the DEX to load pools for.","triggerScenarios":"Calling cache.load_pools(&dex_id) where dex_id was never added via the cache's DEX registration method (e.g. add_dex/register_dex), or after the cache was recreated/reset losing registered DEXes.","commonSituations":"Loading pools on a fresh cache instance without re-registering DEXes first; a typo or wrong variant in DexType; startup ordering where pool loading runs before DEX registration completes.","solutions":["Register the DEX on the cache (e.g. add_dex) before calling load_pools","Fix startup ordering so DEX registration precedes pool loading","Verify the DexType value matches one actually configured/registered (watch for typos or wrong chain)","If the cache is rebuilt at runtime, re-register all DEXes as part of rebuild"],"exampleFix":"// before\nlet pools = cache.load_pools(&DexType::UniswapV3).await?; // never registered\n// after\ncache.add_dex(DexType::UniswapV3, dex_contract).await?;\nlet pools = cache.load_pools(&DexType::UniswapV3).await?;","handlingStrategy":"validation","validationCode":"if cache.get_dex(&dex_id).is_none() {\n    eprintln!(\"DEX {dex_id:?} must be registered before load_pools\");\n}","typeGuard":"fn dex_registered(cache: &BlockchainCache, dex_id: &DexType) -> bool {\n    cache.get_dex(dex_id).is_some()\n}","tryCatchPattern":"match cache.load_pools(&dex_id).await {\n    Err(e) if e.to_string().contains(\"has not been registered\") => {\n        // register the DEX then retry once\n    }\n    other => other?,\n}","preventionTips":["Register all DEXes immediately after cache construction","Enforce registration in an init step that pool loading depends on","Validate DexType values against config at startup","Re-register DEXes whenever the cache is rebuilt"],"tags":["configuration","initialization-order","dex","pools"],"backgroundTag":"resource-not-found","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}