{"record":{"id":"f9ebe38627c188fc","repo":"nautechsystems/nautilus_trader","slug":"default-strategyconfig-should-be-valid","errorCode":null,"errorMessage":"default `StrategyConfig` should be valid","messagePattern":"default `StrategyConfig` should be valid","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/trading/src/strategy/config.rs","lineNumber":233,"sourceCode":")]\n#[cfg_attr(\n    feature = \"python\",\n    pyo3_stub_gen::derive::gen_stub_pyclass(module = \"nautilus_trader.trading\")\n)]\npub struct ImportableStrategyConfig {\n    /// The fully qualified name of the Strategy class.\n    pub strategy_path: String,\n    /// The fully qualified name of the Strategy config class.\n    pub config_path: String,\n    /// The strategy configuration as a dictionary.\n    pub config: HashMap<String, serde_json::Value>,\n}\n\nimpl Default for StrategyConfig {\n    fn default() -> Self {\n        Self::builder()\n            .build()\n            .expect(\"default `StrategyConfig` should be valid\")\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use rstest::rstest;\n    use strum::IntoEnumIterator;\n\n    use super::*;\n\n    #[rstest]\n    fn test_default_config_is_valid() {\n        assert!(StrategyConfig::builder().build().is_ok());\n    }\n\n    #[rstest]\n    fn test_zero_market_exit_interval_rejected() {\n        let result = StrategyConfig::builder().market_exit_interval_ms(0).build();","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/trading/src/strategy/config.rs#L215-L251","documentation":"`Default for StrategyConfig` is implemented by building the config through `StrategyConfig::builder().build()` and `.expect`ing validity. The builder validates all constraints, so if the defaults ever become invalid the Default impl panics instead of returning an invalid config. This is an internal invariant: the library authors promise the default set of fields always passes validation.","triggerScenarios":"Calling `StrategyConfig::default()` (directly or via `Default::default()`) when the crate's default field values violate a builder validation rule — normally only after a code change makes defaults inconsistent with validation.","commonSituations":"Users should essentially never hit this; it surfaces during crate development/downstream forks after editing default values or validation rules so they disagree.","solutions":["If you hit this in a released build, report it as a bug — the shipped defaults must validate","If you modified defaults or validation in a fork, align the default field values with the builder's validation constraints","Bypass `Default` and construct via `StrategyConfig::builder()` with explicit valid values"],"exampleFix":"// before\nlet config = StrategyConfig::default();\n// after: explicit validated construction\nlet config = StrategyConfig::builder()\n    .some_field(valid_value)\n    .build()\n    .expect(\"explicit StrategyConfig should be valid\");","handlingStrategy":"validation","validationCode":"// Verify the default config validates without panicking (compile-time habit / test)\nlet cfg = StrategyConfig::builder().build();\nassert!(cfg.is_ok(), \"default StrategyConfig must validate\");","typeGuard":null,"tryCatchPattern":"// Avoid .default() in contexts where a panic is unacceptable; build explicitly\nlet config = StrategyConfig::builder().build()\n    .map_err(|e| MyError::Config(e.to_string()))?;","preventionTips":["Never edit default field values without rerunning the builder validation tests","Construct configs explicitly with `builder().build()` and handle the Result in application code","Keep validation rules and defaults in the same module so changes stay in sync"],"tags":["rust","config","default","panic","invariant"],"backgroundTag":"internal-invariant-violation","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"}