{"record":{"id":"417a5d15b91094bd","repo":"nautechsystems/nautilus_trader","slug":"invalid-config-type-for-lighterdataclientfactory","errorCode":null,"errorMessage":"Invalid config type for LighterDataClientFactory. Expected LighterDataClientConfig, was {config:?}","messagePattern":"Invalid config type for LighterDataClientFactory\\. Expected LighterDataClientConfig, was (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/lighter/src/factories.rs","lineNumber":83,"sourceCode":"    #[must_use]\n    pub const fn new() -> Self {\n        Self\n    }\n}\n\nimpl DataClientFactory for LighterDataClientFactory {\n    fn create(\n        &self,\n        name: &str,\n        config: &dyn ClientConfig,\n        _cache: CacheView,\n        _clock: Rc<RefCell<dyn Clock>>,\n    ) -> anyhow::Result<Box<dyn DataClient>> {\n        let lighter_config = config\n            .as_any()\n            .downcast_ref::<LighterDataClientConfig>()\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"Invalid config type for LighterDataClientFactory. Expected LighterDataClientConfig, was {config:?}\",\n                )\n            })?\n            .clone();\n\n        let client_id = ClientId::from(name);\n        let client = LighterDataClient::new(client_id, lighter_config)?;\n        Ok(Box::new(client))\n    }\n\n    fn name(&self) -> &'static str {\n        LIGHTER\n    }\n\n    fn config_type(&self) -> &'static str {\n        \"LighterDataClientConfig\"\n    }\n}","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/lighter/src/factories.rs#L65-L101","documentation":"LighterDataClientFactory::create accepts a generic config object and downcasts it to LighterDataClientConfig. If the passed config is any other type (usually another venue's config or a miswired factory/config pairing), the downcast fails and this error is raised naming the expected and actual types.","triggerScenarios":"Registering the Lighter data client factory but passing a different venue's config (e.g. DeribitDataClientConfig) to add_data_client, or a test/test-fixture reusing the wrong config type — as in test_deribit_data_client_factory_creates_client which fed a non-Lighter config into create.","commonSituations":"Copy-pasted node/config builders where the factory name and config type don't match; config parsed from a file that maps to the wrong adapter; tests using a shared config object across venues.","solutions":["Pass a LighterDataClientConfig (deserialize the config section with the Lighter type) when using LighterDataClientFactory.","Check the config source: ensure the config section key actually contains Lighter settings, not another venue's.","Confirm the factory registered under the given name is the Lighter factory and matches the config type.","In tests, construct the config with the correct type for the factory under test."],"exampleFix":"// before\nlet config = DeribitDataClientConfig::default();\nlet factory = LighterDataClientFactory::default();\nfactory.create(\"lighter\", &config, ...)?; // fails: type mismatch\n// after\nlet config = LighterDataClientConfig::default();\nlet factory = LighterDataClientFactory::default();\nfactory.create(\"lighter\", &config, ...)?;","handlingStrategy":"type-guard","validationCode":"let lighter_cfg = config.as_any().downcast_ref::<LighterDataClientConfig>();\nif lighter_cfg.is_none() { /* wrong config type; fix wiring before create */ }","typeGuard":"fn is_lighter_data_config(config: &dyn UserConfig) -> bool {\n    config.as_any().downcast_ref::<LighterDataClientConfig>().is_some()\n}","tryCatchPattern":"match factory.create(name, config, clock) {\n    Err(e) if e.to_string().contains(\"Invalid config type for LighterDataClientFactory\") => {\n        // inspect config type; rebuild with LighterDataClientConfig\n    }\n    other => other,\n}","preventionTips":["Pair each factory with its matching config type at registration time","Type-check the config before calling create in builder code and tests","Avoid sharing one config object across venue factories in tests"],"tags":["factory","config","downcast","lighter"],"backgroundTag":"config-type-mismatch","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"}