{"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/a961cdec3b1948844414ebeecc697dcad76df2d1/ext/cron/01_cron.ts#L127-L163","documentation":"After resolving Deno.cron's overloads, neither the third nor fourth argument position held a function - so there is no handler to run. This fires when only an options object is supplied (and no fourth-argument handler), or when arguments are misordered so the function never lands in a recognized slot.","triggerScenarios":"`Deno.cron(\"n\", \"* * * * *\")`; `Deno.cron(\"n\", \"* * * * *\", { backoffSchedule: [1, 3, 5] })` (options without a fourth-argument handler); embedding the handler inside the options object.","commonSituations":"Forgetting the callback when adding cron jobs; assuming the handler can live inside the options bag; renaming a handler variable so `typeof x === 'function'` fails.","solutions":["Pass the handler: `Deno.cron('n', schedule, handler)`","With options, the handler goes fourth: `Deno.cron('n', schedule, opts, handler)`","Ensure the handler is a plain function reference, not wrapped in an object"],"exampleFix":"// before\nDeno.cron(\"n\", \"* * * * *\", { backoffSchedule: [1, 3, 5] });\n\n// after\nDeno.cron(\"n\", \"* * * * *\", { backoffSchedule: [1, 3, 5] }, runJob);","handlingStrategy":"type-guard","validationCode":"const hasHandler = [handlerOrOptions1, handler2].some((x) => typeof x === \"function\");\nif (!hasHandler) {\n  throw new TypeError(\"cron handler is required\");\n}","typeGuard":"function isCronHandler(x: unknown): x is () => void | Promise<void> {\n  return typeof x === \"function\";\n}","tryCatchPattern":null,"preventionTips":["Always end the call with a function reference","The handler cannot live inside the options object","Prefer the (name, schedule, handler) form unless options are needed"],"tags":["cron","scheduling","missing-callback","deno-cron"],"backgroundTag":"missing-callback","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"}