{"record":{"id":"0c2c96d710ba5a0e","repo":"nautechsystems/nautilus_trader","slug":"default-client-already-registered","errorCode":null,"errorMessage":"default client already registered","messagePattern":"default client already registered","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/data/src/engine/mod.rs","lineNumber":520,"sourceCode":"            \"default client already registered\",\n        )\n        .expect(FAILED);\n\n        let client_id = client.client_id();\n        self.clients.insert(client_id, client);\n        self.default_client_id = Some(client_id);\n        log::debug!(\"Registered default client {client_id}\");\n    }\n\n    /// Marks an already-registered client as the default for fallback routing.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if no client is registered with the given ID, or a different\n    /// client is already the default.\n    pub fn set_default_client(&mut self, client_id: ClientId) -> anyhow::Result<()> {\n        if self.default_client_id.is_some_and(|id| id != client_id) {\n            anyhow::bail!(\"default client already registered\");\n        }\n\n        if !self.clients.contains_key(&client_id) {\n            anyhow::bail!(\"No client registered with ID {client_id}\");\n        }\n        self.default_client_id = Some(client_id);\n        log::debug!(\"Set client {client_id} as default\");\n        Ok(())\n    }\n\n    /// Sets routing for a specific venue to a given client ID.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the client ID is not registered, or the venue is already routed to a\n    /// different client.\n    pub fn register_venue_routing(\n        &mut self,","sourceCodeStart":502,"sourceCodeEnd":538,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/data/src/engine/mod.rs#L502-L538","documentation":"`set_default_client` designates a registered client as the engine's default. This error fires when a different client is already registered as the default — the engine enforces a single default client and refuses to silently replace it. (A second error path in the same method reports an unknown client_id.)","triggerScenarios":"Calling `set_default_client(id_b)` after `set_default_client(id_a)` succeeded, where id_b != id_a. Calling with the currently-default id succeeds (no-op reassignment).","commonSituations":"Initialization code paths running twice and re-attempting default-client setup; multiple components each trying to install their preferred default; config reloading that re-runs registration without checking current state.","solutions":["Check `default_client_id` before calling, or only set the default once during initialization","If replacement is intended, explicitly unset/replace the default via the appropriate API rather than re-setting","Deduplicate initialization logic so competing components don't both set the default","Catch and ignore this error when the intent is 'ensure a default exists' and one is already set"],"exampleFix":"// before\nengine.set_default_client(client_id)?; // may conflict on re-init\n// after\nif engine.default_client_id() != Some(client_id) {\n    engine.set_default_client(client_id)?;\n}","handlingStrategy":"try-catch","validationCode":"if engine.default_client_id().is_some() && engine.default_client_id() != Some(client_id) {\n    // decide: keep existing default or explicitly replace via the proper path\n} else {\n    engine.set_default_client(client_id)?;\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = engine.set_default_client(client_id) {\n    if e.to_string().contains(\"already registered\") {\n        tracing::debug!(\"default client already set; ignoring\");\n    } else {\n        return Err(e);\n    }\n}","preventionTips":["Set the default client exactly once, in a single init path","Make init idempotent: check current state before mutating","Avoid multiple components owning default-client configuration"],"tags":["rust","state","configuration","conflict"],"backgroundTag":"invalid-state-transition","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"}