{"record":{"id":"821da48f2152e2dc","repo":"nautechsystems/nautilus_trader","slug":"data-client-factory-name-is-already-registered","errorCode":null,"errorMessage":"Data client factory '{name}' is already registered","messagePattern":"Data client factory '(.+?)' is already registered","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/common/src/factories/client.rs","lineNumber":154,"sourceCode":"    #[must_use]\n    pub fn new() -> Self {\n        Self {\n            factories: AHashMap::new(),\n        }\n    }\n\n    /// Registers a data client factory.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if a factory with the same name is already registered.\n    pub fn register(\n        &mut self,\n        name: String,\n        factory: Box<dyn DataClientFactory>,\n    ) -> anyhow::Result<()> {\n        if self.factories.contains_key(&name) {\n            anyhow::bail!(\"Data client factory '{name}' is already registered\");\n        }\n\n        self.factories.insert(name, factory);\n        Ok(())\n    }\n\n    /// Gets a registered factory by name.\n    ///\n    /// # Returns\n    ///\n    /// The factory if found, None otherwise.\n    #[must_use]\n    pub fn get(&self, name: &str) -> Option<&dyn DataClientFactory> {\n        self.factories.get(name).map(std::convert::AsRef::as_ref)\n    }\n\n    /// Gets a list of all registered factory names.\n    #[must_use]","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/factories/client.rs#L136-L172","documentation":"The DataClientFactoryRegistry::register method refuses to overwrite an existing factory: if `factories` already contains the given name it bails with this error instead of silently replacing the entry. Factory names act as unique keys, so re-registration under the same name is treated as a programming/config error.","triggerScenarios":"Calling `register(name, factory)` twice with the same `name` on the same DataClientFactoryRegistry instance, e.g. registering built-in factories and then a custom factory using an identical name string.","commonSituations":"Initializing a registry in multiple code paths (module init + user config) that both register the same factory name; a plugin registering a factory name that collides with a built-in; test helpers reusing a global registry across cases without clearing it.","solutions":["Check `factories.contains_key(name)` (or a registry getter) before registering, and skip or log if present.","Use a unique factory name (e.g. namespace it: 'myvendor-binance') instead of a name already in use.","Restructure init so registration happens exactly once per registry instance.","If replacement is genuinely intended, build a new registry or add a replace API rather than re-registering."],"exampleFix":"// before\nregistry.register(\"Binance\".to_string(), my_factory)?;\n\n// after\nif !registry.get(\"Binance\") {\n    registry.register(\"MyVendorBinance\".to_string(), my_factory)?;\n}","handlingStrategy":"validation","validationCode":"// Rust\nfn ensure_absent(registry: &DataClientFactoryRegistry, name: &str) -> anyhow::Result<()> {\n    if registry.contains(name) {\n        anyhow::bail!(\"data factory '{}' already registered; skipping\", name);\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"match registry.register(name.clone(), factory) {\n    Ok(()) => {}\n    Err(e) if e.to_string().contains(\"already registered\") => {\n        log::debug!(\"factory {name} already present; reusing existing\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Register factories from a single init function.","Namespace custom factory names to avoid collisions with built-ins.","Check-before-insert for idempotent setup, especially with shared/global registries."],"tags":["rust","registry","duplicate-key","factory"],"backgroundTag":"file-already-exists","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"}