{"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":5971,"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":5953,"sourceCodeEnd":5989,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/ecc2/src/main.rs#L5953-L5989","documentation":"Thrown by validate_schedule_cron_expr when the cron expression, split on whitespace, does not have 5, 6, or 7 fields. The importer supports standard 5-field cron (to which it prepends '0 ' to make a 6-field expression with seconds), 6-field, and 7-field (with seconds and years) forms. Any other field count is ambiguous and rejected before being passed to the cron parser.","triggerScenarios":"A legacy schedule entry carries a cron expression with too few or too many fields, e.g. '* * *' (3 fields), '0 0 * * 0 extra junk' (6 non-standard tokens), or 'every 5 minutes' (a human-readable string, not cron syntax).","commonSituations":"Migrating from a tool that used a non-standard schedule format (English phrases, intervals like '@daily' not supported here, or quarts-style 6-field without seconds normalization); copy-paste errors; trailing comments or spaces that change the token count.","solutions":["Rewrite the expression as standard 5-field cron 'minute hour day month weekday' (e.g. '0 2 * * *'), or 6/7-field if you need seconds/years.","Remove inline comments or extra tokens so whitespace splitting yields exactly 5, 6, or 7 fields.","Replace human-readable phrases ('every 5 minutes', '@hourly') with their cron equivalent before importing.","Validate locally with a cron checker before re-running the importer."],"exampleFix":"# before\n\"cron\": \"every 5 minutes\"\n\n# after\n\"cron\": \"*/5 * * * *\"","handlingStrategy":"validation","validationCode":"fn cron_field_count_ok(expr: &str) -> bool {\n    matches!(expr.trim().split_whitespace().count(), 5 | 6 | 7)\n}\n\n// usage before import\nif !cron_field_count_ok(&entry.cron) {\n    return Err(anyhow!(\"cron expr has wrong field count: {}\", entry.cron));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use 5-field standard cron unless you specifically need seconds/years.","Avoid human-readable schedule phrases in cron fields.","Lint cron expressions in CI for any schedule config changes."],"tags":["legacy-migration","scheduler","cron","input-validation"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}