{"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/a961cdec3b1948844414ebeecc697dcad76df2d1/ext/cron/01_cron.ts#L104-L140","documentation":"Deno.cron's second parameter - a cron expression string or a structured schedule object - is mandatory. The guard is `schedule === undefined`, throwing before any parsing happens.","triggerScenarios":"`Deno.cron(\"n\", undefined, fn)`; calling with (name, handler) argument order so the schedule slot receives a function reference is NOT caught here (a function is defined) - the pure undefined case is, e.g. schedule loaded from config that is missing.","commonSituations":"Schedule built from config/env that failed to resolve; accidentally passing the handler as the second argument and nothing third; destructuring a schedule object that was renamed.","solutions":["Provide a cron string ('*/5 * * * *') or an object ({ hour: { every: 2 } })","Fix argument order: (name, schedule, handler)","Default or validate config-derived schedules before calling Deno.cron"],"exampleFix":"// before\nDeno.cron(\"n\", undefined, fn);\n\n// after\nDeno.cron(\"n\", \"*/5 * * * *\", fn);","handlingStrategy":"validation","validationCode":"if (schedule === undefined) {\n  throw new TypeError(\"cron schedule is required\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a cron string or schedule object as the second argument","Validate config-loaded schedules before calling Deno.cron","Let TypeScript check the Deno.CronSchedule type at compile time"],"tags":["cron","scheduling","missing-argument","deno-cron"],"backgroundTag":"missing-required-argument","analyzedSha":"a961cdec3b1948844414ebeecc697dcad76df2d1","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}