{"record":{"id":"f3ac4856b381666f","repo":"nautechsystems/nautilus_trader","slug":"invalid-step-in-bar-type-spec-step-step-for-agg","errorCode":null,"errorMessage":"Invalid step in bar_type.spec.step: {step} for aggregation={aggregation}. {reason}","messagePattern":"Invalid step in bar_type\\.spec\\.step: (.+?) for aggregation=(.+?)\\. (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/data/bar.rs","lineNumber":406,"sourceCode":"        .map_err(|_| invalid_interval_step(step, aggregation, \"interval overflows nanoseconds\"))?;\n\n    Ok(duration)\n}\n\nfn try_scaled_days(\n    step: usize,\n    aggregation: BarAggregation,\n    step_i64: i64,\n    multiplier: i64,\n) -> anyhow::Result<SignedDuration> {\n    let days = step_i64\n        .checked_mul(multiplier)\n        .ok_or_else(|| invalid_interval_step(step, aggregation, \"step overflows i64 days\"))?;\n    try_duration_days(days).map_err(|e| invalid_interval_step(step, aggregation, &e.to_string()))\n}\n\nfn invalid_interval_step(step: usize, aggregation: BarAggregation, reason: &str) -> anyhow::Error {\n    anyhow::anyhow!(\n        \"Invalid step in bar_type.spec.step: {step} for aggregation={aggregation}. {reason}\"\n    )\n}\n\n/// Converts a bar specification step to `i64` for time arithmetic.\n///\n/// # Panics\n///\n/// Panics if `step` exceeds the `i64` range.\nfn step_to_i64(step: NonZeroUsize) -> i64 {\n    i64::try_from(step.get()).expect(\"`step` exceeds i64 range\")\n}\n\n/// Represents a bar aggregation specification including a step, aggregation\n/// method/rule and price type.\n#[repr(C)]\n#[derive(\n    Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Debug, Serialize, Deserialize, Builder,","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/data/bar.rs#L388-L424","documentation":"invalid_interval_step builds the canonical error for a bar specification step that cannot be used in time arithmetic: it may overflow i64 when converted, overflow when scaled by a multiplier or into days, or fail SignedDuration conversion. The original reason (e.g. 'step overflows i64 days') is embedded in the message. It guards the time-based bar aggregation machinery against unusable interval configurations.","triggerScenarios":"Constructing bar aggregation intervals (try_time_interval, try_scaled_days) where step exceeds i64, step×multiplier overflows i64 days, or the resulting day count fails try_duration_days — e.g. BarType/BarAggregation specs built from unvalidated user input.","commonSituations":"User/config-provided bar intervals that are zero-negative or astronomically large; programmatic BarType construction with unchecked step values; Python-side integration passing oversized ints into spec.step.","solutions":["Validate bar_type.spec.step is a small positive integer before building the aggregation","Bound step × multiplier against i64 limits in your configuration layer","Handle the returned anyhow::Error and reject the invalid BarType instead of unwrapping"],"exampleFix":"// before\nlet interval = try_time_interval(step, aggregation).unwrap();\n// after\nlet interval = try_time_interval(step, aggregation)\n    .map_err(|e| anyhow::anyhow!(\"bad bar interval: {e}\"))?;","handlingStrategy":"validation","validationCode":"fn step_is_valid(step: usize) -> bool {\n    step > 0 && step <= i64::MAX as usize / 24 / 86_400_000_000 // safely convertible\n}","typeGuard":null,"tryCatchPattern":"let interval = try_time_interval(step, aggregation)\n    .map_err(|e| anyhow::anyhow!(\"invalid bar interval: {e}\"))?;","preventionTips":["Validate spec.step is positive and modest at BarType construction","Never pass unvalidated user/Python integers as steps","Reject invalid intervals at configuration load rather than at runtime arithmetic"],"tags":["rust","bars","configuration","overflow"],"backgroundTag":"invalid-argument-value","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"}