{"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/89f33cbef296a2b287f323d42de54c871fa69c77/ext/cron/01_cron.ts#L99-L135","documentation":"Deno.cron(name, schedule, handlerOrOptions?, handler2?) requires a unique job name as the first argument; the name identifies the job across process restarts. An undefined name throws before anything else is validated.","triggerScenarios":"Deno.cron(undefined as any, '* * * * *', fn); swapping argument order (schedule first); spreading a config object whose name key is missing.","commonSituations":"Dynamic job registration from configuration or CLI flags where the name was never set.","solutions":["Pass a stable unique string: Deno.cron('nightly-cleanup', '* * * * *', fn).","Validate config at load time: if (!name) throw with a message naming the missing key."],"exampleFix":"// before\nDeno.cron(cfg.jobName, '* * * * *', fn); // cfg.jobName is undefined\n// after\nif (!cfg.jobName) throw new Error('cron job requires cfg.jobName');\nDeno.cron(cfg.jobName, '* * * * *', fn);","handlingStrategy":"validation","validationCode":"if (typeof name !== 'string' || name.length === 0) {\n  throw new Error('cron job name is required');\n}\nDeno.cron(name, schedule, handler);","typeGuard":"function isCronName(v: unknown): v is string {\n  return typeof v === 'string' && v.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Validate cron job config (name, schedule) at config-load time with clear messages.","Keep the (name, schedule, handler) order explicit; avoid positional spreads into Deno.cron."],"tags":["cron","scheduling","validation","configuration"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}