risingwavelabs/risingwave · error · InvalidParamsError

Invalid date: days: {days}

Error message

Invalid date: days: {days}

What it means

ErrorKind::Date is an internal error kind in RisingWave's datetime type conversion (src/common/src/types/datetime.rs) indicating that a day-count value cannot represent a valid date. Converting days (relative to the epoch used by chrono) into a NaiveDate failed because the day count is outside the representable date range, and the library surfaces it formatted as 'Invalid date: days: <i32>'.

Source

Thrown at src/common/src/types/datetime.rs:249

/// let time = Time::from(interval);
/// assert_eq!(time, Time::from_str("00:01:01.000003").unwrap());
///
/// let interval = Interval::from_month_day_usec(0, 0, -61000003);
/// let time = Time::from(interval);
/// assert_eq!(time, Time::from_str("23:58:58.999997").unwrap());
/// ```
impl From<Interval> for Time {
    fn from(interval: Interval) -> Self {
        let usecs = interval.usecs_of_day();
        let secs = (usecs / 1_000_000) as u32;
        let nano = (usecs % 1_000_000 * 1000) as u32;
        Time::from_num_seconds_from_midnight_uncheck(secs, nano)
    }
}

#[derive(Copy, Clone, Debug, Error)]
enum ErrorKind {
    #[error("Invalid date: days: {days}")]
    Date { days: i32 },
    #[error("Invalid time: secs: {secs}, nanoseconds: {nsecs}")]
    Time { secs: u32, nsecs: u32 },
    #[error("Invalid time: {value} {unit} is out of range for a time of day")]
    TimeOfDay { value: u64, unit: &'static str },
    #[error("Invalid datetime: seconds: {secs}, nanoseconds: {nsecs}")]
    DateTime { secs: i64, nsecs: u32 },
    #[error("Invalid datetime: {value} {unit} is out of range")]
    Timestamp { value: i64, unit: &'static str },
    #[error("Can't cast string to date (expected format is YYYY-MM-DD)")]
    ParseDate,
    #[error(
        "Can't cast string to time (expected format is HH:MM:SS[.D+{{up to 6 digits}}][Z] or HH:MM)"
    )]
    ParseTime,
    #[error(
        "Can't cast string to timestamp (expected format is YYYY-MM-DD HH:MM:SS[.D+{{up to 9 digits}}] or YYYY-MM-DD HH:MM or YYYY-MM-DD or ISO 8601 format)"
    )]

View on GitHub (pinned to 6469eb736d)

Solutions

  1. Validate the day count is within chrono's supported NaiveDate range before conversion.
  2. Check the interval/date arithmetic in the query for overflow-inducing operands.
  3. Sanitize or bound incoming numeric data before casting to date.

Example fix

// before
let date = Date::from_days(overflowing_days);
// after
let date = if days >= MIN_DAYS && days <= MAX_DAYS {
    Date::from_days(days)
} else {
    return Err(ErrorCode::InvalidInputValue(format!("days {} out of range", days)));
};
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check day count against the representable date range
const MIN_DAYS: i32 = i32::MIN / 4; // conservatively inside chrono's range
const MAX_DAYS: i32 = i32::MAX / 4;
fn days_in_range(days: i32) -> bool { (MIN_DAYS..=MAX_DAYS).contains(&days) }

Try / catch

match Date::from_days(days) {
    Ok(d) => d,
    Err(e) if e.to_string().starts_with("Invalid date: days") => {
        // fall back to NULL / sentinel date and log the raw value
        log::warn!("unrepresentable date days={days}");
        Date::default()
    }
    Err(e) => return Err(e.into()),
}

Prevention

When it happens

Trigger: Calling date/timestamp conversion helpers such as Date::from_days or similar ToNaiveDate paths in src/common/src/types/datetime.rs with an i32 day count outside chrono's NaiveDate range (roughly days corresponding to years outside ~-262144..262143), e.g. from extreme interval arithmetic or corrupted input values.

Common situations: Arithmetic on dates/intervals that overflows (subtracting huge intervals); casting out-of-range numbers to date; upstream data containing garbage numeric date values.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of risingwavelabs/risingwave@6469eb736d (2026-09-11). Data as JSON: /api/errors/bf2ff9557c54df47. Report an issue: GitHub.