denoland/deno · error · TypeError
Cannot create cron job, a single handler is required: two ha
Error message
Cannot create cron job, a single handler is required: two handlers were specified
What it means
Deno.cron accepts either (name, schedule, handler) or (name, schedule, options, handler). When the third argument is a function, the fourth argument must be absent; supplying both counts as two handlers and throws.
Source
Thrown at ext/cron/01_cron.ts:137
);
}
if (schedule === undefined) {
throw new TypeError(
"Cannot create cron job, a schedule is required: received 'undefined'",
);
}
schedule = parseScheduleToString(schedule);
let handler: () => Promise<void> | void;
let options:
| { backoffSchedule?: number[]; signal?: AbortSignal }
| undefined = undefined;
if (typeof handlerOrOptions1 === "function") {
handler = handlerOrOptions1;
if (handler2 !== undefined) {
throw new TypeError(
"Cannot create cron job, a single handler is required: two handlers were specified",
);
}
} else if (typeof handler2 === "function") {
handler = handler2;
options = handlerOrOptions1;
} else {
throw new TypeError("Cannot create cron job: a handler is required");
}
const rid = op_cron_create(
name,
schedule,
options?.backoffSchedule,
);
if (options?.signal) {
const signal = options?.signal;View on GitHub (pinned to 89f33cbef2)
Solutions
- Delete the extra handler argument.
- If options (backoffSchedule, signal) are needed, make the third argument the options object and the fourth the single handler.
Example fix
// before
Deno.cron('n', '* * * * *', runA, runB);
// after
Deno.cron('n', '* * * * *', runA); Defensive patterns
Strategy: validation
Validate before calling
if (typeof handlerOrOptions1 === 'function' && handler2 !== undefined) {
throw new Error('pass exactly one handler');
}
Deno.cron(name, schedule, handlerOrOptions1, handler2); Prevention
- Use one of the two supported shapes only: (name, schedule, handler) or (name, schedule, options, handler).
- Do not add completion callbacks — Deno.cron has none.
When it happens
Trigger: Deno.cron('n', '* * * * *', fn, fn2) — any fourth argument alongside a function third argument.
Common situations: Copy-paste from an older or imagined API with a completion callback; merging two code paths that each supplied a handler.
Related errors
- Invalid cron schedule: start=${start}, end=${end}, every=${e
- Cannot create cron job, a unique name is required: received
- Cannot create cron job, a schedule is required: received 'un
- Cannot create cron job: a handler is required
- Delay must be >= 0: received ${delay}
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/0b41650cea49b525.
Report an issue: GitHub.