{"record":{"id":"76780cf165d0abd7","repo":"Hmbown/CodeWhale","slug":"cron-expr-day-of-month-month-combination-can-never","errorCode":null,"errorMessage":"CRON EXPR day-of-month/month combination can never occur","messagePattern":"CRON EXPR day-of-month/month combination can never occur","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/automation_manager.rs","lineNumber":708,"sourceCode":"            day_of_month || weekday\n        }\n    }\n\n    fn validate_date_space(&self) -> Result<()> {\n        if self.day_of_month.is_wildcard {\n            return Ok(());\n        }\n        let months = self.month.values();\n        let days = self.day_of_month.values();\n        let valid = months.iter().copied().any(|month| {\n            let common = days_in_month(2025, month);\n            let leap = days_in_month(2024, month);\n            days.iter().copied().any(|day| day <= common || day <= leap)\n        });\n        if valid {\n            Ok(())\n        } else {\n            bail!(\"CRON EXPR day-of-month/month combination can never occur\")\n        }\n    }\n}\n\n#[derive(Debug, Clone)]\nstruct CronField {\n    values: Vec<u32>,\n    is_wildcard: bool,\n}\n\nimpl CronField {\n    fn parse(raw: &str, min: u32, max: u32, names: CronNameMap, field_name: &str) -> Result<Self> {\n        let trimmed = raw.trim();\n        if trimmed.is_empty() {\n            bail!(\"CRON {field_name} field must not be empty\");\n        }\n        let mut values = Vec::new();\n        let is_wildcard = trimmed == \"*\";","sourceCodeStart":690,"sourceCodeEnd":726,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/automation_manager.rs#L690-L726","documentation":"validate_date_space runs after field parsing when day-of-month is not a wildcard: for each listed month it checks that at least one listed day is <= that month's day count in 2024 (leap) or 2025 (common). If no month/day pair can ever exist, the expression is rejected as unmatchable. '0 0 29 2 *' passes because Feb 29 exists in leap years; '0 0 30 2 *' and '0 0 31 4 *' fail.","triggerScenarios":"EXPR='0 0 31 4 *' (April 31); '0 0 30 2 *' (Feb 30); '0 0 31 4,6,9,11 *' (day 31 restricted to 30-day months).","commonSituations":"End-of-month crontabs applied blindly to every month; generated expressions enumerating day 31 for monthly tasks.","solutions":["Restrict the month field to months that have the day, e.g. '0 0 31 1,3,5,7,8,10,12 *'","Or use a range like 28-31 and verify the month length inside the task","Remember February contributes at most 29; Feb-29-only rules then face the 5-year search limit","Dry-run parse_rrule to catch this at configuration time"],"exampleFix":"// before (April 31 does not exist)\nrrule = \"FREQ=CRON;EXPR=0 0 31 4 *\"\n\n// after (31st only in 31-day months)\nrrule = \"FREQ=CRON;EXPR=0 0 31 1,3,5,7,8,10,12 *\"","handlingStrategy":"validation","validationCode":"fn cron_expr_valid(expr: &str) -> bool {\n    AutomationSchedule::parse_rrule(&format!(\"FREQ=CRON;EXPR={expr}\")).is_ok()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate end-of-month schedules with month-aware logic","Remember February contributes at most 29 days","Validate EXPR through parse_rrule before saving","Prefer ranges like 28-31 plus in-task date checks over a bare 31"],"tags":["rust","cron","calendar","validation"],"backgroundTag":"cron-impossible-date-combination","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}