{"record":{"id":"33bd0387c52d7a96","repo":"affaan-m/ECC","slug":"invalid-cron-expression-trimmed-expected-5-6-33bd03","errorCode":null,"errorMessage":"invalid cron expression `{trimmed}`: expected 5, 6, or 7 fields but found {fields}","messagePattern":"invalid cron expression `(.+?)`: expected 5, 6, or 7 fields but found (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"ecc2/src/session/manager.rs","lineNumber":2365,"sourceCode":"}\n\nfn resolve_session(db: &StateStore, id: &str) -> Result<Session> {\n    let session = if id == \"latest\" {\n        db.get_latest_session()?\n    } else {\n        db.get_session(id)?\n    };\n\n    session.ok_or_else(|| anyhow::anyhow!(\"Session not found: {id}\"))\n}\n\nfn parse_cron_schedule(expr: &str) -> Result<CronSchedule> {\n    let trimmed = expr.trim();\n    let normalized = match trimmed.split_whitespace().count() {\n        5 => format!(\"0 {trimmed}\"),\n        6 | 7 => trimmed.to_string(),\n        fields => {\n            anyhow::bail!(\n                \"invalid cron expression `{trimmed}`: expected 5, 6, or 7 fields but found {fields}\"\n            )\n        }\n    };\n    CronSchedule::from_str(&normalized)\n        .with_context(|| format!(\"invalid cron expression `{trimmed}`\"))\n}\n\nfn next_schedule_run_at(\n    expr: &str,\n    after: chrono::DateTime<chrono::Utc>,\n) -> Result<chrono::DateTime<chrono::Utc>> {\n    parse_cron_schedule(expr)?\n        .after(&after)\n        .next()\n        .map(|value| value.with_timezone(&chrono::Utc))\n        .ok_or_else(|| anyhow::anyhow!(\"cron expression `{expr}` did not yield a future run time\"))\n}","sourceCodeStart":2347,"sourceCodeEnd":2383,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/ecc2/src/session/manager.rs#L2347-L2383","documentation":"The parse_cron_schedule function normalizes cron expressions before passing them to CronSchedule::from_str. It expects exactly 5, 6, or 7 whitespace-separated fields. Five-field expressions (traditional Unix cron) get a '0 ' prefix for seconds. Anything else is rejected as malformed.","triggerScenarios":"Passing a cron expression to parse_cron_schedule or next_schedule_run_at that does not have exactly 5, 6, or 7 whitespace-separated fields.","commonSituations":"Typo in schedule config (e.g., extra spaces counted as fields, missing field). Using a non-standard cron dialect. Copy-paste error from documentation that uses dashes instead of spaces. Empty schedule string.","solutions":["Ensure the cron expression has exactly 5 fields (min hour day month weekday), 6 (with seconds), or 7 (with seconds and years)","Trim and validate the expression's field count before scheduling","Check for accidental double-spaces or tabs that split_whitespace would count as extra fields","Use a cron expression validator or linter in config tooling"],"exampleFix":"// before\nlet schedule = parse_cron_schedule(\"0 9 * *\")?;\n\n// after\nlet schedule = parse_cron_schedule(\"0 9 * * *\")?;  // 5 fields: min hour day month weekday","handlingStrategy":"validation","validationCode":"fn validate_cron_fields(expr: &str) -> Result<()> {\n    let count = expr.trim().split_whitespace().count();\n    match count {\n        5 | 6 | 7 => Ok(()),\n        n => Err(anyhow!(\"cron expression must have 5, 6, or 7 fields, found {n}\")),\n    }\n}","typeGuard":"fn is_valid_cron_field_count(expr: &str) -> bool {\n    matches!(expr.trim().split_whitespace().count(), 5 | 6 | 7)\n}","tryCatchPattern":null,"preventionTips":["Validate cron expressions at config-load time rather than at first scheduling","Use cron expression linters or validators in configuration tooling","Document the expected field count for your cron dialect in config templates"],"tags":["cron","scheduling","validation","configuration"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}