{"record":{"id":"06775de36da310a4","repo":"denoland/deno","slug":"cannot-create-cron-job-a-unique-name-is-required","errorCode":null,"errorMessage":"Cannot create cron job, a unique name is required: received 'undefined'","messagePattern":"Cannot create cron job, a unique name is required: received 'undefined'","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/cron/01_cron.ts","lineNumber":117,"sourceCode":"\n    return formatToCronSchedule(minute) +\n      \" \" + formatToCronSchedule(hour) +\n      \" \" + formatToCronSchedule(dayOfMonth) +\n      \" \" + formatToCronSchedule(month) +\n      \" \" + 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;","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/denoland/deno/blob/a961cdec3b1948844414ebeecc697dcad76df2d1/ext/cron/01_cron.ts#L99-L135","documentation":"Deno.cron's first parameter is the unique job name (used to deduplicate jobs across runs of the same code). The check is `name === undefined`, so a completely missing/undefined name throws immediately, while an empty string would pass this guard but still defeats deduplication.","triggerScenarios":"`Deno.cron(undefined, \"* * * * *\", fn)` - typically a name variable that failed to initialize, or arguments passed in the wrong order (schedule first, name second).","commonSituations":"Name read from an env var or config key that is absent; refactoring that swapped the name and schedule parameters; generated job code where the name template produced undefined.","solutions":["Pass a stable, unique name string first: `Deno.cron('my-job', schedule, handler)`","If the name comes from config, default it: `Deno.cron(name ?? 'my-job', ...)`","Re-check the argument order: (name, schedule, handler) or (name, schedule, options, handler)"],"exampleFix":"// before\nDeno.cron(process.env.JOB_NAME, \"* * * * *\", fn); // env var unset -> undefined\n\n// after\nDeno.cron(Deno.env.get(\"JOB_NAME\") ?? \"fallback-job\", \"* * * * *\", fn);","handlingStrategy":"validation","validationCode":"if (name === undefined) {\n  throw new TypeError(\"cron name is required\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the (name, schedule, handler) argument order","Default config-derived names: name ?? 'fallback-job'","Use non-empty stable identifiers so deduplication works across deployments"],"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"}