{"record":{"id":"85d88d1b49690110","repo":"affaan-m/ECC","slug":"invalid-cron-expression-trimmed-expected-5-6","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/main.rs","lineNumber":5970,"sourceCode":"}\n\nfn shell_quote_double(value: &str) -> String {\n    format!(\n        \"\\\"{}\\\"\",\n        value\n            .replace('\\\\', \"\\\\\\\\\")\n            .replace('\"', \"\\\\\\\"\")\n            .replace('\\n', \"\\\\n\")\n    )\n}\n\nfn validate_schedule_cron_expr(expr: &str) -> Result<()> {\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    <cron::Schedule as std::str::FromStr>::from_str(&normalized)\n        .with_context(|| format!(\"invalid cron expression `{trimmed}`\"))?;\n    Ok(())\n}\n\nfn build_legacy_schedule_add_command(draft: &LegacyScheduleDraft) -> Option<String> {\n    let cron_expr = draft.cron_expr.as_deref()?;\n    let task = draft.task.as_deref()?;\n    let mut parts = vec![\n        \"ecc schedule add\".to_string(),\n        format!(\"--cron {}\", shell_quote_double(cron_expr)),\n        format!(\"--task {}\", shell_quote_double(task)),\n    ];\n    if let Some(agent) = draft.agent.as_deref() {","sourceCodeStart":5952,"sourceCodeEnd":5988,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/main.rs#L5952-L5988","documentation":"`validate_schedule_cron_expr` counts whitespace-separated fields in the cron expression and requires 5 (minute-based, auto-prefixed with seconds `0 `), 6, or 7 (with seconds/optional year). Any other count bails with the trimmed expression and the actual field count. The normalized expression is then parsed by the `cron` crate.","triggerScenarios":"Entering a 4-field cron (`0 12 * * *` style with a dropped field), a 3-field shorthand (`daily`-style ranges), or an expression where spaces inside a field (e.g. an unquoted `* * * * * * * *`) inflate the count.","commonSituations":"Copy-pasting a cron from a tool that uses a different field count (some schedulers use 6-field with seconds, others 5); hand-editing a cron and dropping a field; pasting human text like `every day at noon` or `@daily` descriptors that aren't field-based cron.","solutions":["Count the fields in your expression; make it 5 fields (min hour dom mon dow) for standard cron.","Add seconds explicitly as the first field if you need sub-minute precision (6 fields), or seconds + year (7 fields).","Replace `@daily`/`@hourly` descriptors with their explicit 5-field equivalents (`0 0 * * *`, `0 * * * *`).","Quote or escape any field content containing spaces so it isn't split into extra fields."],"exampleFix":"// before\nvalidate_schedule_cron_expr(\"0 12 * *\")?; // 4 fields\n\n// after\nvalidate_schedule_cron_expr(\"0 12 * * *\")?; // 5 fields","handlingStrategy":"validation","validationCode":"// Count cron fields before validating\nfn cron_field_count(expr: &str) -> usize {\n    expr.trim().split_whitespace().count()\n}\nassert!((5..=7).contains(&cron_field_count(expr)));","typeGuard":"fn is_valid_cron_field_count(expr: &str) -> bool {\n    matches!(expr.trim().split_whitespace().count(), 5 | 6 | 7)\n}","tryCatchPattern":"match validate_schedule_cron_expr(expr) {\n    Err(e) if e.to_string().contains(\"expected 5, 6, or 7 fields\") => {\n        eprintln!(\"Fix cron fields in: {expr}\");\n    }\n    other => other?,\n}","preventionTips":["Use a cron-builder library or UI picker rather than hand-writing expressions.","Expand @-descriptors (@daily, @hourly) to explicit 5-field cron before storing.","Unit-test stored schedule expressions at config load time."],"tags":["cron","validation","rust"],"backgroundTag":"invalid-argument-format","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}