nautechsystems/nautilus_trader · error
Invalid config type for LighterDataClientFactory. Expected L
Error message
Invalid config type for LighterDataClientFactory. Expected LighterDataClientConfig, was {config:?} What it means
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.
Source
Thrown at crates/adapters/lighter/src/factories.rs:83
#[must_use]
pub const fn new() -> Self {
Self
}
}
impl DataClientFactory for LighterDataClientFactory {
fn create(
&self,
name: &str,
config: &dyn ClientConfig,
_cache: CacheView,
_clock: Rc<RefCell<dyn Clock>>,
) -> anyhow::Result<Box<dyn DataClient>> {
let lighter_config = config
.as_any()
.downcast_ref::<LighterDataClientConfig>()
.ok_or_else(|| {
anyhow::anyhow!(
"Invalid config type for LighterDataClientFactory. Expected LighterDataClientConfig, was {config:?}",
)
})?
.clone();
let client_id = ClientId::from(name);
let client = LighterDataClient::new(client_id, lighter_config)?;
Ok(Box::new(client))
}
fn name(&self) -> &'static str {
LIGHTER
}
fn config_type(&self) -> &'static str {
"LighterDataClientConfig"
}
}View on GitHub (pinned to 18893faf8b)
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.
Example fix
// before
let config = DeribitDataClientConfig::default();
let factory = LighterDataClientFactory::default();
factory.create("lighter", &config, ...)?; // fails: type mismatch
// after
let config = LighterDataClientConfig::default();
let factory = LighterDataClientFactory::default();
factory.create("lighter", &config, ...)?; Defensive patterns
Strategy: type-guard
Validate before calling
let lighter_cfg = config.as_any().downcast_ref::<LighterDataClientConfig>();
if lighter_cfg.is_none() { /* wrong config type; fix wiring before create */ } Type guard
fn is_lighter_data_config(config: &dyn UserConfig) -> bool {
config.as_any().downcast_ref::<LighterDataClientConfig>().is_some()
} Try / catch
match factory.create(name, config, clock) {
Err(e) if e.to_string().contains("Invalid config type for LighterDataClientFactory") => {
// inspect config type; rebuild with LighterDataClientConfig
}
other => other,
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid config type for BetfairDataClientFactory. Expected B
- Invalid config type for BetfairExecutionClientFactory. Expec
- Invalid config type for BitmexDataClientFactory. Expected Bi
- Invalid config type for BitmexExecutionClientFactory. Expect
- Invalid config type for BlockchainDataClientFactory. Expecte
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/417a5d15b91094bd.
Report an issue: GitHub.