nautechsystems/nautilus_trader · info

valid year start date

Error message

valid year start date

What it means

In `get_time_bar_start` (crates/model/src/data/bar.rs:262), the Month branch anchors to Jan 1 of the current year: `Date::new(now_civil.year(), 1, 1).expect("valid year start date")`. This panics if the year is outside jiff's supported calendar range (roughly -9999..9999), which cannot happen for real Unix timestamps.

Source

Thrown at crates/model/src/data/bar.rs:262

            let mut start_time = Offset::UTC
                .to_timestamp(week_start_date.at(0, 0, 0, 0))
                .expect("valid UTC week start");
            start_time += origin_offset;

            if now < start_time {
                start_time -=
                    duration_days(step.checked_mul(7).expect("`step` overflows i64 days"));
            }

            start_time
        }
        BarAggregation::Month => {
            // Set to the first day of the year
            let now_civil = Offset::UTC.to_datetime(now);
            let mut start_time = Offset::UTC
                .to_timestamp(
                    Date::new(now_civil.year(), 1, 1)
                        .expect("valid year start date")
                        .at(0, 0, 0, 0),
                )
                .expect("valid UTC year start");
            start_time += origin_offset;

            if now < start_time {
                start_time =
                    subtract_n_months(start_time, 12).expect("Failed to subtract 12 months");
            }

            let months_step =
                u32::try_from(step).expect("`step` exceeds u32 range for month arithmetic");

            while start_time <= now {
                start_time =
                    add_n_months(start_time, months_step).expect("Failed to add months in loop");
            }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. No action needed for real timestamps.
  2. If hit, verify the `now` UnixTimestamp passed in is not corrupted.
  3. Report to maintainers with the offending timestamp if encountered.
Defensive patterns

Strategy: type-guard

Validate before calling

// rust
fn timestamp_in_reasonable_range(now: UnixNanos) -> bool {
    let secs = now.as_u64() / 1_000_000_000;
    secs > 0 && secs < 253_402_300_799
}

Prevention

When it happens

Trigger: Effectively unreachable for valid timestamps; would require `now` to decode to a civil year outside jiff's Date range.

Common situations: Corrupted or synthetic clock values; no realistic production path.

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


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/19351fdf5e7c96bc. Report an issue: GitHub.