{"record":{"id":"e65c42c32c6f8ea5","repo":"nautechsystems/nautilus_trader","slug":"invalid-config-type-for-sandboxexecutionclientfact","errorCode":null,"errorMessage":"Invalid config type for SandboxExecutionClientFactory. Expected SandboxExecutionClientConfig, was {config:?}","messagePattern":"Invalid config type for SandboxExecutionClientFactory\\. Expected SandboxExecutionClientConfig, was (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/sandbox/src/factory.rs","lineNumber":74,"sourceCode":"    #[must_use]\n    pub const fn new() -> Self {\n        Self\n    }\n}\n\nimpl SimulatedExecutionClientFactory for SandboxExecutionClientFactory {\n    fn create(\n        &self,\n        trader_id: TraderId,\n        name: &str,\n        config: &dyn ClientConfig,\n        cache: Rc<RefCell<Cache>>,\n    ) -> anyhow::Result<Box<dyn ExecutionClient>> {\n        let sandbox_config = config\n            .as_any()\n            .downcast_ref::<SandboxExecutionClientConfig>()\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"Invalid config type for SandboxExecutionClientFactory. Expected SandboxExecutionClientConfig, was {config:?}\",\n                )\n            })?\n            .clone();\n\n        let client_id = ClientId::from(name);\n        let clock: Rc<RefCell<dyn Clock>> = Rc::new(RefCell::new(LiveClock::default()));\n\n        let core = ExecutionClientCore::new(\n            trader_id,\n            client_id,\n            sandbox_config.venue,\n            sandbox_config.oms_type,\n            sandbox_config.account_id,\n            sandbox_config.account_type,\n            sandbox_config.base_currency,\n            cache.clone(),\n        );","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/sandbox/src/factory.rs#L56-L92","documentation":"SandboxExecutionClientFactory.create receives a generic config object and downcasts it to SandboxExecutionClientConfig. If the registered config is any other type (wrong factory for the config, or config built from the wrong builder), the downcast fails and this error names the actual config received via Debug formatting.","triggerScenarios":"Registering SandboxExecutionClientFactory with an ExecutionClientConfig of a different concrete type — e.g. passing LiveExecutionClientConfig, BacktestExecutionClientConfig, or a hand-built config struct into the factory's create().","commonSituations":"Copy-pasted factory registration in client setup code pairing the wrong factory with a config; programmatic node assembly where builders were mixed up; renaming/refactors that changed config types.","solutions":["Read the Debug output in the message to see which config type was actually passed","Ensure the config passed to the factory is created via SandboxExecutionClientConfig / its builder","Fix the factory-to-config pairing in your registration code (use SandboxExecutionClientFactory only with SandboxExecutionClientConfig)","Check for typos between similar sandbox config types if multiple exist"],"exampleFix":"// before: wrong config type for the factory\nlet config = LiveExecutionClientConfig::new(...);\nlet client = SandboxExecutionClientFactory.create(name, config, ...);\n// after\nlet config = SandboxExecutionClientConfig::new(...);\nlet client = SandboxExecutionClientFactory.create(name, config, ...);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"fn is_sandbox_config(config: &dyn ExecutionClientConfig) -> bool {\n    config.as_any().downcast_ref::<SandboxExecutionClientConfig>().is_some()\n}","tryCatchPattern":"let client = match factory.create(name, config, cache) {\n    Ok(c) => c,\n    Err(e) if e.to_string().contains(\"Invalid config type\") => {\n        panic!(\"config/factory mismatch: {e}\") // fix registration, don't retry\n    }\n    Err(e) => return Err(e.into()),\n};","preventionTips":["Pair each factory with its exact config type in registration code","Build configs via the matching *Config builder","Check the Debug name in the error to spot the wrong type immediately"],"tags":["sandbox","factory","config","type-mismatch"],"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-14T05:17:10.506Z"}