jlcodes99/cockpit-tools · warning
invalid_crontab_number
invalid_crontab_number
Error message
invalid_crontab_number
What it means
parseCrontabNumber in WakeupTasksPage parses a crontab field token with parseInt and throws Error('invalid_crontab_number') when the token is not a valid integer. It is part of the page's custom cron-expression parser used when building wakeup-task schedules.
Source
Thrown at src/pages/WakeupTasksPage.tsx:442
interface ParsedCronField {
values: Set<number>;
wildcard: boolean;
}
interface ParsedCrontab {
minute: ParsedCronField;
hour: ParsedCronField;
dayOfMonth: ParsedCronField;
month: ParsedCronField;
dayOfWeek: ParsedCronField;
}
const normalizeCrontabDayOfWeek = (value: number) => (value === 7 ? 0 : value);
const parseCrontabNumber = (raw: string): number => {
const parsed = Number.parseInt(raw.trim(), 10);
if (Number.isNaN(parsed)) {
throw new Error('invalid_crontab_number');
}
return parsed;
};
const validateCrontabValue = (
value: number,
min: number,
max: number,
normalizeDayOfWeek: boolean,
) => {
if (normalizeDayOfWeek && value === 7) return;
if (value < min || value > max) {
throw new Error('crontab_value_out_of_range');
}
};
const insertCrontabRange = (
target: Set<number>,View on GitHub (pinned to 1ed8b77992)
Solutions
- Correct the crontab expression so every field is a valid integer or supported range/step syntax the parser accepts.
- Use the UI's field pickers instead of free-typing the cron string to generate valid values.
- Validate the expression with the same parse logic before saving to catch the bad token early.
- Catch the parse error and show which field/token failed so the user can fix it.
Example fix
// before
parseCronExpression('30 * * * MON'); // throws invalid_crontab_number
// after
parseCronExpression('30 * * * 1'); // day-of-week as number Defensive patterns
Strategy: validation
Validate before calling
const isValidCronToken = (raw: string) => /^\d+$/.test(raw.trim()) && !Number.isNaN(Number.parseInt(raw.trim(), 10)); // run over every numeric token before parsing/saving the expression
Type guard
const isNumericToken = (raw: string): raw is `${number}` =>
/^\d+$/.test(raw.trim()); Try / catch
try {
const expr = parseCronExpression(input);
save(expr);
} catch (e) {
if (e.message === 'invalid_crontab_number') {
showFieldError('cron', '每一段必须是有效数字(不支持 * / 名称等语法)');
return;
}
throw e;
} Prevention
- Prefer the UI field pickers over free-text cron editing.
- Reject or expand unsupported syntax ('*', names like MON) before parse.
- Validate the whole expression with the app's own parser before persisting.
When it happens
Trigger: A crontab expression field (minute/hour/day/month/day-of-week, or a range/step component) contains a token that parseInt cannot convert to a number — e.g. '*', letters, '1-*/2' components reaching the numeric path, or empty strings from double commas.
Common situations: User hand-edits the cron string into the input and types invalid characters; a saved expression from an older version or another scheduler uses syntax this parser doesn't accept (e.g. '*', 'L', names like 'MON'); copy-pasted expressions with stray whitespace/symbols.
Related errors
- invalidJsonMessage
- crontab_value_out_of_range
- messages.invalidJson
- messages.noItems
- messages.providerMismatch
AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05).
Data as JSON: /api/errors/be784acd3da9c014.
Report an issue: GitHub.