{"record":{"id":"6286211eb334fd31","repo":"paperclipai/paperclip","slug":"cron-expression-must-have-exactly-5-fields-got","errorCode":null,"errorMessage":"Cron expression must have exactly 5 fields, got ${tokens.length}: \"${trimmed}\"","messagePattern":"Cron expression must have exactly 5 fields, got (.+?): \"(.+?)\"","errorType":"validation","errorClass":"Error","httpStatus":422,"severity":"error","filePath":"server/src/services/cron.ts","lineNumber":212,"sourceCode":" * @returns Parsed cron with sorted valid values for each field.\n * @throws {Error} on invalid syntax.\n *\n * @example\n * ```ts\n * const parsed = parseCron(\"0 * * * *\"); // every hour at minute 0\n * // parsed.minutes === [0]\n * // parsed.hours === [0,1,2,...,23]\n * ```\n */\nexport function parseCron(expression: string): ParsedCron {\n  const trimmed = expression.trim();\n  if (!trimmed) {\n    throw new Error(\"Cron expression must not be empty\");\n  }\n\n  const tokens = trimmed.split(/\\s+/);\n  if (tokens.length !== 5) {\n    throw new Error(\n      `Cron expression must have exactly 5 fields, got ${tokens.length}: \"${trimmed}\"`,\n    );\n  }\n\n  return {\n    minutes: parseField(tokens[0]!, FIELD_SPECS[0]!),\n    hours: parseField(tokens[1]!, FIELD_SPECS[1]!),\n    daysOfMonth: parseField(tokens[2]!, FIELD_SPECS[2]!),\n    months: parseField(tokens[3]!, FIELD_SPECS[3]!),\n    daysOfWeek: parseField(tokens[4]!, FIELD_SPECS[4]!),\n  };\n}\n\n/**\n * Validate a cron expression string. Returns `null` if valid, or an error\n * message string if invalid.\n *\n * @param expression — A cron expression string to validate.","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/paperclipai/paperclip/blob/120ae5428fa29bee300bcf806491cd4d965fbb7c/server/src/services/cron.ts#L194-L230","documentation":"Shape guard in parseCron: after whitespace-splitting, the expression does not have exactly 5 tokens (minute hour dom month dow). The message reports the actual token count and the full trimmed expression so the fix is obvious.","triggerScenarios":"Thrown at server/src/services/cron.ts:212 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use exactly 5 fields (minute hour day-of-month month day-of-week) in the cron expression."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"120ae5428fa29bee300bcf806491cd4d965fbb7c","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}