{"record":{"id":"f74edcb10cb8d836","repo":"jlcodes99/cockpit-tools","slug":"crontab-value-out-of-range","errorCode":"crontab_value_out_of_range","errorMessage":"crontab_value_out_of_range","messagePattern":"crontab_value_out_of_range","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/pages/WakeupTasksPage.tsx","lineNumber":455,"sourceCode":"const normalizeCrontabDayOfWeek = (value: number) => (value === 7 ? 0 : value);\n\nconst parseCrontabNumber = (raw: string): number => {\n  const parsed = Number.parseInt(raw.trim(), 10);\n  if (Number.isNaN(parsed)) {\n    throw new Error('invalid_crontab_number');\n  }\n  return parsed;\n};\n\nconst validateCrontabValue = (\n  value: number,\n  min: number,\n  max: number,\n  normalizeDayOfWeek: boolean,\n) => {\n  if (normalizeDayOfWeek && value === 7) return;\n  if (value < min || value > max) {\n    throw new Error('crontab_value_out_of_range');\n  }\n};\n\nconst insertCrontabRange = (\n  target: Set<number>,\n  start: number,\n  end: number,\n  step: number,\n  normalizeDayOfWeek: boolean,\n) => {\n  for (let value = start; value <= end; value += step) {\n    target.add(normalizeDayOfWeek ? normalizeCrontabDayOfWeek(value) : value);\n  }\n};\n\nconst parseCrontabSegment = (\n  segment: string,\n  min: number,","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/pages/WakeupTasksPage.tsx#L437-L473","documentation":"validateCrontabValue in WakeupTasksPage checks that a parsed crontab field value lies within [min, max] for its unit; out-of-range values throw Error('crontab_value_out_of_range'). Day-of-week 7 is tolerated only when normalizeDayOfWeek is true (it is normalized to 0 elsewhere).","triggerScenarios":"A crontab field contains a numeric value outside the unit's valid range — e.g. minute 60+, hour 24+, day-of-month 32+, month 13+, day-of-week 8+ — or day-of-week 7 with normalizeDayOfWeek false.","commonSituations":"User types 25 for hour or 8 for day-of-week in the free-text cron input; expressions copied from schedulers with looser rules (7 = Sunday) hit strict validation; off-by-one mistakes when hand-assembling ranges like '0-60/5'.","solutions":["Fix the out-of-range value: minutes 0-59, hours 0-23, day-of-month 1-31, months 1-12, day-of-week 0-7 (7 normalized to Sunday where supported).","Use the page's field pickers to generate in-range values instead of editing the cron string directly.","Replace day-of-week 7 with 0 if the validation path doesn't normalize it.","Validate the expression before save and show the offending field to the user."],"exampleFix":"// before\n'0 0 * * 8' // throws crontab_value_out_of_range\n// after\n'0 0 * * 0' // Sunday as 0","handlingStrategy":"validation","validationCode":"const CRON_RANGES = { minute: [0,59], hour: [0,23], dom: [1,31], month: [1,12], dow: [0,7] } as const;\nconst inRange = (v: number, [min, max]: readonly [number, number]) => v >= min && v <= max;","typeGuard":null,"tryCatchPattern":"try {\n  saveCron(expression);\n} catch (e) {\n  if (e.message === 'crontab_value_out_of_range') {\n    showFieldError('cron', '字段值超出允许范围');\n    return;\n  }\n  throw e;\n}","preventionTips":["Clamp or reject values against per-field ranges before building the expression.","Replace day-of-week 7 with 0 when the parser's normalizeDayOfWeek is off.","Use bounded pickers so users cannot enter values outside the valid range."],"tags":["cron","range-validation","parsing"],"backgroundTag":"invalid-crontab-syntax","analyzedSha":"1ed8b77992d62ca81fabf744deb0839ad361d5bf","analyzedAt":"2026-09-05T09:51:41.178Z","contentChangedAt":"2026-09-05T09:51:41.178Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}