{"record":{"id":"96a1bb17c2fdd424","repo":"anomalyco/sst","slug":"you-must-provide-either-a-function-or-a-task-in-th","errorCode":null,"errorMessage":"You must provide either a function or a task in the \"${name}\" CronV2 component.","messagePattern":"You must provide either a function or a task in the \"(.+?)\" CronV2 component\\.","errorType":"exception","errorClass":"VisibleError","httpStatus":null,"severity":"error","filePath":"platform/src/components/aws/cron-v2.ts","lineNumber":340,"sourceCode":"    this._schedule = schedule;\n\n    function normalizeFunction() {\n      if (args.job && args.function)\n        throw new VisibleError(\n          `You cannot provide both \"job\" and \"function\" in the \"${name}\" CronV2 component. The \"job\" property has been deprecated. Use \"function\" instead.`,\n        );\n\n      const input = args.function ?? args.job;\n      return input ? output(input) : undefined;\n    }\n\n    function normalizeTargets() {\n      if (fnArgs && args.task)\n        throw new VisibleError(\n          `You cannot provide both a function and a task in the \"${name}\" CronV2 component.`,\n        );\n      if (!fnArgs && !args.task)\n        throw new VisibleError(\n          `You must provide either a function or a task in the \"${name}\" CronV2 component.`,\n        );\n    }\n\n    function createFunction() {\n      if (!fnArgs) return;\n\n      return fnArgs.apply((fnArgs) =>\n        functionBuilder(`${name}Handler`, fnArgs, {}, undefined, {\n          parent,\n        }),\n      );\n    }\n\n    function createRole() {\n      if (fn) {\n        return new iam.Role(\n          ...transform(","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/platform/src/components/aws/cron-v2.ts#L322-L358","documentation":"CronV2 requires exactly one schedule target. This error is thrown in normalizeTargets when neither a `function`/`job` nor a `task` is provided, so the schedule would be created with nothing to invoke.","triggerScenarios":"`new sst.aws.CronV2(name, { schedule })` with no `function`, `job`, or `task` in args — e.g. an empty args object or all target keys commented out.","commonSituations":"Scaffolding a cron and forgetting to wire the handler; commenting out the function while debugging; a dynamically built args object that ends up empty due to a false conditional.","solutions":["Add a `function` property pointing to a function/linkable handler","Add a `task` property pointing to an ECS task if the job should run in ECS","If the cron is not yet implemented, comment out the whole CronV2 component until the handler exists"],"exampleFix":"// before\nnew sst.aws.CronV2(\"MyCron\", {\n  schedule: \"rate(1 day)\",\n});\n// after\nnew sst.aws.CronV2(\"MyCron\", {\n  schedule: \"rate(1 day)\",\n  function: handler,\n});","handlingStrategy":"validation","validationCode":"function validateCronV2Target(args: sst.aws.CronV2Args) {\n  if (!args.function && !args.job && !args.task)\n    throw new Error(\"CronV2 requires a 'function' or 'task' target\");\n}","typeGuard":"function hasTarget(args: { function?: unknown; job?: unknown; task?: unknown }): boolean {\n  return Boolean(args.function ?? args.job ?? args.task);\n}","tryCatchPattern":"try {\n  new sst.aws.CronV2(\"MyCron\", args);\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"must provide either a function or a task\")) {\n    console.error(\"Add a function or task target to the cron\");\n  } else throw e;\n}","preventionTips":["Always wire the handler when scaffolding a cron; use a stub function if not implemented yet","Avoid building cron args dynamically without a default target","Comment out the whole component if the handler is temporarily removed"],"tags":["config","validation","cron","missing-argument"],"backgroundTag":"missing-required-prop","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}