{"record":{"id":"0b41650cea49b525","repo":"denoland/deno","slug":"cannot-create-cron-job-a-single-handler-is-requir","errorCode":null,"errorMessage":"Cannot create cron job, a single handler is required: two handlers were specified","messagePattern":"Cannot create cron job, a single handler is required: two handlers were specified","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/cron/01_cron.ts","lineNumber":137,"sourceCode":"    );\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    }\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;","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/denoland/deno/blob/a961cdec3b1948844414ebeecc697dcad76df2d1/ext/cron/01_cron.ts#L119-L155","documentation":"Deno.cron has two overloads: (name, schedule, handler) and (name, schedule, options, handler). If the third argument is a function AND a fourth argument is also supplied (not undefined), the implementation cannot tell which is the handler and throws the 'two handlers' TypeError.","triggerScenarios":"`Deno.cron(\"n\", \"* * * * *\", fn, fn2)`; or passing (name, schedule, handler, options) in the wrong order so both the third and fourth slots contain functions.","commonSituations":"Migrating from an API shape that took options fourth and handler third; copy-paste duplication of the callback; refactoring call sites between the two overloads.","solutions":["Use exactly one handler: `Deno.cron('n', schedule, fn)` or `Deno.cron('n', schedule, { backoffSchedule, signal }, fn)`","Delete the duplicate function argument"],"exampleFix":"// before\nDeno.cron(\"n\", \"* * * * *\", fn, { backoffSchedule: [1, 3, 5] }); // options in handler slot\n\n// after\nDeno.cron(\"n\", \"* * * * *\", { backoffSchedule: [1, 3, 5] }, fn);","handlingStrategy":"validation","validationCode":"const fns = [handlerOrOptions1, handler2].filter((x) => typeof x === \"function\");\nif (fns.length > 1) {\n  throw new TypeError(\"pass at most one handler\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use one overload consistently: (name, schedule, fn) or (name, schedule, opts, fn)","Options go third and handler fourth - never both function positions","Delete copy-pasted duplicate callbacks during refactors"],"tags":["cron","scheduling","arguments","deno-cron"],"backgroundTag":"duplicate-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"}