paperclipai/paperclip · error · Error
Cron expression must have exactly 5 fields, got ${tokens.len
Error message
Cron expression must have exactly 5 fields, got ${tokens.length}: "${trimmed}" What it means
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.
Source
Thrown at server/src/services/cron.ts:212
* @returns Parsed cron with sorted valid values for each field.
* @throws {Error} on invalid syntax.
*
* @example
* ```ts
* const parsed = parseCron("0 * * * *"); // every hour at minute 0
* // parsed.minutes === [0]
* // parsed.hours === [0,1,2,...,23]
* ```
*/
export function parseCron(expression: string): ParsedCron {
const trimmed = expression.trim();
if (!trimmed) {
throw new Error("Cron expression must not be empty");
}
const tokens = trimmed.split(/\s+/);
if (tokens.length !== 5) {
throw new Error(
`Cron expression must have exactly 5 fields, got ${tokens.length}: "${trimmed}"`,
);
}
return {
minutes: parseField(tokens[0]!, FIELD_SPECS[0]!),
hours: parseField(tokens[1]!, FIELD_SPECS[1]!),
daysOfMonth: parseField(tokens[2]!, FIELD_SPECS[2]!),
months: parseField(tokens[3]!, FIELD_SPECS[3]!),
daysOfWeek: parseField(tokens[4]!, FIELD_SPECS[4]!),
};
}
/**
* Validate a cron expression string. Returns `null` if valid, or an error
* message string if invalid.
*
* @param expression — A cron expression string to validate.View on GitHub (pinned to 120ae5428f)
Solutions
- Use exactly 5 fields (minute hour day-of-month month day-of-week) in the cron expression.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at server/src/services/cron.ts:212 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of paperclipai/paperclip@120ae5428f (2026-08-18).
Data as JSON: /api/errors/6286211eb334fd31.
Report an issue: GitHub.