{"record":{"id":"674506071562b04c","repo":"denoland/deno","slug":"cannot-create-cron-job-a-handler-is-required","errorCode":null,"errorMessage":"Cannot create cron job: a handler is required","messagePattern":"Cannot create cron job: a handler is required","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/cron/01_cron.ts","lineNumber":145,"sourceCode":"  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    }\n  } else if (typeof handler2 === \"function\") {\n    handler = handler2;\n    options = handlerOrOptions1;\n  } else {\n    throw new TypeError(\"Cannot create cron job: a handler is required\");\n  }\n\n  const rid = op_cron_create(\n    name,\n    schedule,\n    options?.backoffSchedule,\n  );\n\n  if (options?.signal) {\n    const signal = options?.signal;\n    signal.addEventListener(\n      \"abort\",\n      () => {\n        core.close(rid);\n      },\n      { once: true },\n    );\n  }","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/cron/01_cron.ts#L127-L163","documentation":"If neither the third nor the fourth argument to Deno.cron is a function, no handler exists and cron creation throws. The handler is what the scheduler invokes on each tick.","triggerScenarios":"Deno.cron('n', '* * * * *') with no third argument; Deno.cron('n', sched, { backoffSchedule: [1000] }) with options but no handler function.","commonSituations":"Passing options but forgetting the handler; a handler variable that is undefined due to an import or naming mistake.","solutions":["Pass the handler function: Deno.cron('n', sched, () => { ... }).","With options: Deno.cron('n', sched, { backoffSchedule: [1000] }, handler).","Check the handler import resolves: typeof handler === 'function'."],"exampleFix":"// before\nDeno.cron('n', '* * * * *');\n// after\nDeno.cron('n', '* * * * *', async () => {\n  await runJob();\n});","handlingStrategy":"validation","validationCode":"const handler = typeof handlerOrOptions1 === 'function' ? handlerOrOptions1 : handler2;\nif (typeof handler !== 'function') {\n  throw new Error('cron job requires a handler function');\n}","typeGuard":"function isCronHandler(v: unknown): v is () => void | Promise<void> {\n  return typeof v === 'function';\n}","tryCatchPattern":null,"preventionTips":["Assert typeof handler === 'function' before registering dynamic jobs.","Check imports: a wrong or missing import yields undefined and lands on this error."],"tags":["cron","scheduling","validation","handler"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}