diesel-rs/diesel · critical
Maximal supported day interval size is 32 bit
Error message
Maximal supported day interval size is 32 bit
What it means
Diesel's PgInterval stores the `days` field as i32. The `days()` method on interval builder integers converts the caller's integer (commonly i64) via `i32::try_from(self)` and panics with this message if the value does not fit in 32 bits. This is a runtime panic (an .expect), not a recoverable error.
Solutions
- Validate the day count fits in i32 before calling .days() (value.abs() <= i32::MAX as i64).
- Break large intervals into months/years: use .months() or .years() for big spans (also i32-bounded but larger effective range).
- Clamp the interval to the maximum representable days before building the PgInterval.
- Catch at a higher level: run interval construction behind a checked conversion so invalid input is rejected by app validation, not a panic.
Example fix
// before
let interval = duration_days_i64.days(); // panics if > i32::MAX
// after
let days = i32::try_from(duration_days_i64)
.map_err(|_| anyhow::anyhow!("interval too large"))?;
let interval = days.days(); Defensive patterns
Strategy: validation
Validate before calling
fn fits_i32(v: i64) -> bool { v >= i32::MIN as i64 && v <= i32::MAX as i64 }
// guard: if fits_i32(days) { days.days() } else { split into months/years } Type guard
fn as_day_count(v: i64) -> Option<i32> { i32::try_from(v).ok() } Try / catch
// .expect() panics; you cannot catch it. Validate instead: let days = i32::try_from(raw_days).map_err(|_| Error::IntervalTooLarge)?; let interval = days.days();
Prevention
- Range-check day/month values against i32 bounds before building intervals.
- Express large durations in months or years via the DSL.
- Never feed unvalidated user input straight into .days()/.months().
When it happens
Trigger: Calling e.g. `(1i64 << 40).days()` or any value > i32::MAX (2,147,483,647) / < i32::MIN on the interval DSL's days() builder.
Common situations: Computing a day count dynamically (multiplying years by 365 in i64) and passing it to days(); overflow after unit changes from weeks/months to days; user-supplied large durations.
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
- Unable to perform MySQL global initialization
- not implemented
- DIESEL_MAX_COLUMN_COUNT is a number that fits into a u16
- Using window functions in WHERE clauses is not supported
- Error closing SQLite connection
AI-assisted analysis of diesel-rs/diesel@6fa6ed01b2 (2026-09-07).
Data as JSON: /api/errors/e63606b5b44e5456.
Report an issue: GitHub.
Appendix: source
Thrown at diesel/src/pg/expression/extensions/interval_dsl.rs:223
}
fn minutes(self) -> PgInterval {
i64::from(self).minutes()
}
fn hours(self) -> PgInterval {
i64::from(self).hours()
}
}
impl IntervalDsl for i64 {
fn microseconds(self) -> PgInterval {
PgInterval::from_microseconds(self)
}
fn days(self) -> PgInterval {
i32::try_from(self)
.expect("Maximal supported day interval size is 32 bit")
.days()
}
fn months(self) -> PgInterval {
i32::try_from(self)
.expect("Maximal supported month interval size is 32 bit")
.months()
}
}
#[allow(clippy::cast_possible_truncation)] // we want to truncate
impl IntervalDsl for f64 {
fn microseconds(self) -> PgInterval {
(self.round() as i64).microseconds()
}
fn days(self) -> PgInterval {
let fractional_days = (self.fract() * 86_400.0).seconds();View on GitHub (pinned to 6fa6ed01b2)