nautechsystems/nautilus_trader · error
default `PortfolioConfig` should be valid
Error message
default `PortfolioConfig` should be valid
What it means
Default for PortfolioConfig builds via the typed builder and unwraps, asserting the library's own defaults satisfy all builder validation rules. This panic indicates a library bug: the default configuration became invalid relative to its builder invariants.
Source
Thrown at crates/portfolio/src/config.rs:145
errors.check(
ms > 0,
ConfigError::range(
field,
format!("must be a positive number of milliseconds, was {ms}"),
),
);
}
}
errors.into_result()
}
}
impl Default for PortfolioConfig {
fn default() -> Self {
Self::builder()
.build()
.expect("default `PortfolioConfig` should be valid")
}
}
#[cfg(test)]
mod tests {
use rstest::rstest;
use super::*;
#[rstest]
fn test_default_config_is_valid() {
assert!(PortfolioConfig::builder().build().is_ok());
}
#[rstest]
fn test_default_config_enables_daily_equity_curve_only() {
let config = PortfolioConfig::default();
View on GitHub (pinned to 18893faf8b)
Solutions
- Update all nautilus crates to a consistent version (cargo update).
- Reproduce with an explicit builder call to see which field fails validation.
- Report as a library bug — the default must always be valid.
Example fix
// before
let config = PortfolioConfig::default(); // panics if defaults invalid
// after
let config = PortfolioConfig::builder()
.build()
.unwrap_or_else(|e| panic!("portfolio default invalid: {e}")); // inspect the failing field Defensive patterns
Strategy: validation
Validate before calling
// verify builder validity explicitly to surface the failing field
let cfg = PortfolioConfig::builder().build();
if let Err(e) = &cfg { eprintln!("portfolio config invalid: {e}"); } Try / catch
let result = std::panic::catch_unwind(PortfolioConfig::default);
Prevention
- Keep all nautilus crate versions aligned
- Prefer explicit builder construction in tests to see validation errors
- Report defaults that fail validation as upstream bugs
When it happens
Trigger: Calling PortfolioConfig::default() (directly or via ..Default::default() in configs) — panics only if the builder rejects the default field values, e.g. after a version change introduced new validated fields.
Common situations: Mixing crate versions (model/portfolio mismatch) where defaults no longer satisfy validation; a regression in the portfolio crate after adding a new required/validated config option.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- external message bus factory cannot be combined with injecte
- NautilusKernelBuilder cannot consume external message bus st
- default `StrategyConfig` should be valid
- Invalid config type for AxExecutionClientFactory. Expected A
- Invalid factory address for DEX {name} on chain {chain} for
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/f253a9a5f8f18370.
Report an issue: GitHub.