Hmbown/CodeWhale · error · anyhow::Error

CRON value is out of range

Error message

CRON {field_name} value {value} is out of range {min}-{max}

What it means

After resolving a field atom (either via the name map, e.g. month/weekday names, or numeric parse), parse_cron_atom checks the value against the field's allowed min..=max and rejects out-of-range values. This is the bounds check for validly-formatted numbers like 60 in minutes or 13 in a 1-12 month field.

Solutions

  1. Move the value into the field's documented range, e.g. month 12 not 13, minute 59 not 60
  2. Check the numbering convention for named fields (cron months are 1-12, weekdays 0-7 with 0=Sunday)
  3. Fix the source variable or config value producing the out-of-range number

Example fix

// before
"0 0 * * 8" // weekday 8 out of range
// after
"0 0 * * 0" // Sunday (0-6)
Defensive patterns

Strategy: validation

Validate before calling

fn in_range(v: u32, min: u32, max: u32) -> bool { (min..=max).contains(&v) }
assert!(in_range(minute, 0, 59));

Prevention

When it happens

Trigger: A value that parses as u32 but exceeds the field's range: minute 60+, hour 24+, day-of-month 0 or 32+, month 13+, weekday 8+ (given the field's min/max).

Common situations: Off-by-one confusion (months 0-11 vs 1-12; hours 0-23 vs 1-24); typo '0 0 * * 9' for weekday; reusing seconds-style 0-59 values in a minute field.

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 Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/f53787383c3c4d40. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/automation_manager.rs:960

        self.0
            .iter()
            .find_map(|(name, value)| (*name == needle).then_some(*value))
    }
}

fn parse_cron_atom(
    raw: &str,
    min: u32,
    max: u32,
    names: CronNameMap,
    field_name: &str,
) -> Result<u32> {
    let value = names
        .lookup(raw)
        .or_else(|| raw.parse::<u32>().ok())
        .ok_or_else(|| anyhow::anyhow!("Invalid CRON {field_name} value '{raw}'"))?;
    if !(min..=max).contains(&value) {
        bail!("CRON {field_name} value {value} is out of range {min}-{max}");
    }
    Ok(value)
}

fn weekday_to_cron(day: Weekday) -> u32 {
    match day {
        Weekday::Sun => 0,
        Weekday::Mon => 1,
        Weekday::Tue => 2,
        Weekday::Wed => 3,
        Weekday::Thu => 4,
        Weekday::Fri => 5,
        Weekday::Sat => 6,
    }
}

fn days_in_month(year: i32, month: u32) -> u32 {
    match month {

View on GitHub (pinned to 73e0f67d83)