nautechsystems/nautilus_trader · error
default `StrategyConfig` should be valid
Error message
default `StrategyConfig` should be valid
What it means
`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.
Source
Thrown at crates/trading/src/strategy/config.rs:233
)]
#[cfg_attr(
feature = "python",
pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.trading")
)]
pub struct ImportableStrategyConfig {
/// The fully qualified name of the Strategy class.
pub strategy_path: String,
/// The fully qualified name of the Strategy config class.
pub config_path: String,
/// The strategy configuration as a dictionary.
pub config: HashMap<String, serde_json::Value>,
}
impl Default for StrategyConfig {
fn default() -> Self {
Self::builder()
.build()
.expect("default `StrategyConfig` should be valid")
}
}
#[cfg(test)]
mod tests {
use rstest::rstest;
use strum::IntoEnumIterator;
use super::*;
#[rstest]
fn test_default_config_is_valid() {
assert!(StrategyConfig::builder().build().is_ok());
}
#[rstest]
fn test_zero_market_exit_interval_rejected() {
let result = StrategyConfig::builder().market_exit_interval_ms(0).build();View on GitHub (pinned to 18893faf8b)
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
Example fix
// before
let config = StrategyConfig::default();
// after: explicit validated construction
let config = StrategyConfig::builder()
.some_field(valid_value)
.build()
.expect("explicit StrategyConfig should be valid"); Defensive patterns
Strategy: validation
Validate before calling
// Verify the default config validates without panicking (compile-time habit / test) let cfg = StrategyConfig::builder().build(); assert!(cfg.is_ok(), "default StrategyConfig must validate");
Try / catch
// Avoid .default() in contexts where a panic is unacceptable; build explicitly
let config = StrategyConfig::builder().build()
.map_err(|e| MyError::Config(e.to_string()))?; Prevention
- 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
When it happens
Trigger: 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.
Common situations: Users should essentially never hit this; it surfaces during crate development/downstream forks after editing default values or validation rules so they disagree.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Close command should not be drained
- Flush command should not be drained
- Invalid factory address for DEX {name} on chain {chain} for
- Order invariant violated: first event must be OrderInitializ
- API key is valid UTF-8
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/f9ebe38627c188fc.
Report an issue: GitHub.