{"record":{"id":"6a1ce4055a42df86","repo":"Hmbown/CodeWhale","slug":"unable-to-construct-hourly-anchor","errorCode":null,"errorMessage":"Unable to construct HOURLY anchor","messagePattern":"Unable to construct HOURLY anchor","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/automation_manager.rs","lineNumber":499,"sourceCode":"                        \"Once schedule has no future run after {}\",\n                        after.to_rfc3339()\n                    )\n                }\n            }\n            Self::Hourly {\n                interval_hours,\n                byday,\n                anchor_hour,\n                anchor_minute,\n            } => {\n                if anchor_hour.is_some() || anchor_minute.is_some() {\n                    let local_anchor_reference = anchor_reference.with_timezone(timezone);\n                    let hour = anchor_hour.unwrap_or(local_anchor_reference.hour());\n                    let minute = anchor_minute.unwrap_or(0);\n                    let anchor_naive = local_anchor_reference\n                        .date_naive()\n                        .and_hms_opt(hour, minute, 0)\n                        .ok_or_else(|| anyhow::anyhow!(\"Unable to construct HOURLY anchor\"))?;\n                    let interval_seconds = i64::from(*interval_hours) * 60 * 60;\n                    let elapsed_seconds = local_after\n                        .naive_local()\n                        .signed_duration_since(anchor_naive)\n                        .num_seconds();\n                    let mut steps = if elapsed_seconds < 0 {\n                        0\n                    } else {\n                        elapsed_seconds / interval_seconds + 1\n                    };\n\n                    for _ in 0..MAX_HOURLY_SEARCH_STEPS {\n                        let hours = i64::from(*interval_hours)\n                            .checked_mul(steps)\n                            .ok_or_else(|| anyhow::anyhow!(\"HOURLY schedule exceeded its range\"))?;\n                        let delta = Duration::try_hours(hours)\n                            .ok_or_else(|| anyhow::anyhow!(\"HOURLY schedule exceeded its range\"))?;\n                        let candidate_naive = anchor_naive","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/automation_manager.rs#L481-L517","documentation":"When computing the next run of a HOURLY automation, the code builds an anchor datetime from the anchor date plus (hour, minute, 0) via chrono's and_hms_opt; if that combination is invalid (impossible time-of-day) construction fails with this error.","triggerScenarios":"A HOURLY schedule whose configured hour or minute is out of the valid range (hour > 23 or minute > 59), producing None from and_hms_opt; the anchor date itself is valid, so only the time fields can be at fault.","commonSituations":"Hand-edited schedule config with BYHOUR=24 or BYMINUTE=60, config written by another tool with overflow values, timezone anchor reference combined with unvalidated user input.","solutions":["Fix the schedule's hour/minute values to hour 0-23 and minute 0-59","Validate BYHOUR/BYMINUTE ranges at schedule-creation time before persisting","Re-save the automation through the UI/CLI so values are range-checked"],"exampleFix":"// before: unvalidated config\n{ \"freq\": \"HOURLY\", \"intervalHours\": 2, \"hour\": 24, \"minute\": 0 }\n// after: validate before use\nassert!((0..=23).contains(&hour) && (0..=59).contains(&minute), \"invalid HOURLY anchor time\");","handlingStrategy":"validation","validationCode":"fn valid_hourly_time(hour: u32, minute: u32) -> bool {\n    hour <= 23 && minute <= 59\n}\n// call before creating/updating a HOURLY automation\nif !valid_hourly_time(hour, minute) { bail!(\"HOURLY time out of range\"); }","typeGuard":"fn is_valid_time(t: &(u32, u32)) -> bool { t.0 <= 23 && t.1 <= 59 }","tryCatchPattern":"match next_run(&schedule, after) {\n    Ok(r) => r,\n    Err(e) if e.to_string().contains(\"Unable to construct HOURLY anchor\") => {\n        eprintln!(\"Schedule time-of-day invalid; fix hour/minute in config\");\n        ScheduleError::BadAnchor\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Validate hour 0-23 and minute 0-59 at schedule creation","Never write raw hour/minute values from untrusted input into schedule config","Add a config-load check that rejects impossible times early (fail loud)","Round-trip test schedules after editing config by hand"],"tags":["automation","scheduling","chrono","datetime"],"backgroundTag":"value-out-of-range","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}