{"record":{"id":"11f2424599159377","repo":"denoland/deno","slug":"cannot-create-cron-job-a-schedule-is-required-re","errorCode":null,"errorMessage":"Cannot create cron job, a schedule is required: received 'undefined'","messagePattern":"Cannot create cron job, a schedule is required: received 'undefined'","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/cron/01_cron.ts","lineNumber":122,"sourceCode":"      \" \" + formatToCronSchedule(dayOfWeek);\n  }\n}\n\nfunction cron(\n  name: string,\n  schedule: string | Deno.CronSchedule,\n  handlerOrOptions1:\n    | (() => Promise<void> | void)\n    | ({ backoffSchedule?: number[]; signal?: AbortSignal }),\n  handler2?: () => Promise<void> | void,\n) {\n  if (name === undefined) {\n    throw new TypeError(\n      \"Cannot create cron job, a unique name is required: received 'undefined'\",\n    );\n  }\n  if (schedule === undefined) {\n    throw new TypeError(\n      \"Cannot create cron job, a schedule is required: received 'undefined'\",\n    );\n  }\n\n  schedule = parseScheduleToString(schedule);\n\n  let handler: () => Promise<void> | void;\n  let options:\n    | { backoffSchedule?: number[]; signal?: AbortSignal }\n    | undefined = undefined;\n\n  if (typeof handlerOrOptions1 === \"function\") {\n    handler = handlerOrOptions1;\n    if (handler2 !== undefined) {\n      throw new TypeError(\n        \"Cannot create cron job, a single handler is required: two handlers were specified\",\n      );\n    }","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/cron/01_cron.ts#L104-L140","documentation":"The second argument to Deno.cron is mandatory: a cron expression string ('*/5 * * * *') or a Deno.CronSchedule object. An undefined schedule throws before the job is created.","triggerScenarios":"Deno.cron('n', undefined, fn); omitting the schedule argument entirely.","commonSituations":"Optional schedule settings in config; refactors that changed the parameter list.","solutions":["Pass a cron string or schedule object as the second argument.","Validate that the schedule config exists before registering the job."],"exampleFix":"// before\nDeno.cron('n', cfg.schedule, fn); // cfg.schedule is undefined\n// after\nif (!cfg.schedule) throw new Error('cron job requires cfg.schedule');\nDeno.cron('n', cfg.schedule, fn);","handlingStrategy":"validation","validationCode":"if (schedule === undefined) {\n  throw new Error('cron job schedule is required');\n}\nDeno.cron(name, schedule, handler);","typeGuard":"function isCronScheduleValue(v: unknown): v is string | Deno.CronSchedule {\n  return typeof v === 'string' || (typeof v === 'object' && v !== null);\n}","tryCatchPattern":null,"preventionTips":["Give config types non-optional schedule fields for jobs you intend to register.","Fail fast at startup on missing schedule config rather than inside Deno.cron."],"tags":["cron","scheduling","validation","configuration"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}