{"record":{"id":"e45bd25d63241fdf","repo":"nautechsystems/nautilus_trader","slug":"executionalgorithmconfig-must-have-exec-algorithm","errorCode":null,"errorMessage":"ExecutionAlgorithmConfig must have exec_algorithm_id set","messagePattern":"ExecutionAlgorithmConfig must have exec_algorithm_id set","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/trading/src/algorithm/core.rs","lineNumber":145,"sourceCode":"            .field(\n                \"strategy_event_handlers\",\n                &self.strategy_event_handlers.len(),\n            )\n            .finish()\n    }\n}\n\nimpl ExecutionAlgorithmCore {\n    /// Creates a new [`ExecutionAlgorithmCore`] instance.\n    ///\n    /// # Panics\n    ///\n    /// Panics if `config.exec_algorithm_id` is `None`.\n    #[must_use]\n    pub fn new(config: ExecutionAlgorithmConfig) -> Self {\n        let exec_algorithm_id = config\n            .exec_algorithm_id\n            .expect(\"ExecutionAlgorithmConfig must have exec_algorithm_id set\");\n\n        let actor_config = DataActorConfig {\n            actor_id: Some(ActorId::new(exec_algorithm_id.inner())),\n            log_events: config.log_events,\n            log_commands: config.log_commands,\n        };\n\n        Self {\n            actor: DataActorCore::new(actor_config),\n            config,\n            exec_algorithm_id,\n            exec_spawn_ids: AHashMap::new(),\n            subscribed_strategies: AHashSet::new(),\n            pending_spawn_reductions: AHashMap::new(),\n            submit_params: AHashMap::new(),\n            portfolio: None,\n            strategy_event_handlers: IndexMap::new(),\n        }","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/trading/src/algorithm/core.rs#L127-L163","documentation":"ExecutionAlgorithmConfig::new panics via `expect` when the config has no `exec_algorithm_id`, because the algorithm cannot be constructed without an identifier. The type technically allows `None` (probably to satisfy a shared config struct), but this constructor requires it. It is an eager invariant check: fail fast at construction instead of deep inside the actor machinery.","triggerScenarios":"Calling `ExecutionAlgorithmConfig::new(config)` (or `ExecutionAlgorithm::new(config)`) where `config.exec_algorithm_id` is `None` — e.g. building the config programmatically from optional CLI/JSON fields, or deserializing a config file that omitted the `exec_algorithm_id` key.","commonSituations":"Loading a TOML/JSON execution algorithm config where the id field is optional and missing; constructing a default config before assigning an id; copying config-building code that sets logging flags but never the id; migrating code that used to infer the id elsewhere.","solutions":["Set `exec_algorithm_id: Some(ExecAlgorithmId::from(\"MY_ALGO\"))` (or parse from string) before calling `new`.","Validate the config at load/deserialization time and reject it with a clear error before reaching this constructor.","Build the config from a fully-populated source (typed deserialization with required field) rather than partial defaults.","If the id truly cannot be known yet, defer construction until it is available instead of calling `new` with a placeholder-less config."],"exampleFix":"// before\nlet config = ExecutionAlgorithmConfig {\n    exec_algorithm_id: None,\n    log_events: true,\n    log_commands: true,\n};\nlet algo = ExecutionAlgorithm::new(config); // panics\n\n// after\nlet config = ExecutionAlgorithmConfig {\n    exec_algorithm_id: Some(ExecAlgorithmId::from(\"EXEC_ALARM\")),\n    log_events: true,\n    log_commands: true,\n};\nlet algo = ExecutionAlgorithm::new(config);","handlingStrategy":"validation","validationCode":"// Rust\nfn validate_exec_algorithm_config(config: &ExecutionAlgorithmConfig) -> Result<(), String> {\n    if config.exec_algorithm_id.is_none() {\n        return Err(\"exec_algorithm_id is required\".to_string());\n    }\n    Ok(())\n}\nvalidate_exec_algorithm_config(&config)?;\nlet algo = ExecutionAlgorithm::new(config);","typeGuard":"fn has_exec_algorithm_id(config: &ExecutionAlgorithmConfig) -> bool {\n    config.exec_algorithm_id.is_some()\n}","tryCatchPattern":null,"preventionTips":["Deserialize configs into types where exec_algorithm_id is required (Option-free) whenever possible.","Validate all config fields immediately after loading, before constructing any actors.","Write a unit test that feeds a config with a missing id and asserts your loader rejects it."],"tags":["rust","panic","config","execution-algorithm"],"backgroundTag":"missing-required-config-field","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"}