no-throw-in-transform - ESLint plugin rules
This rule disallows throw statements inside a transform() callback.
Severity#
error. This rule is enabled in the recommended preset.
What it Targets#
This rule targets files in your project's src/workflows directory. It reports throw statements placed directly inside a transform() callback.
The following code is reported by the rule:
1import {2 createWorkflow,3 transform,4 WorkflowResponse,5} from "@medusajs/framework/workflows-sdk"6 7createWorkflow("my-workflow", (input) => {8 const value = transform({ input }, (data) => {9 if (!data.input.foo) {10 throw new Error("invalid")11 }12 return data.input.foo13 })14 15 return new WorkflowResponse(value)16})
Instead, use a validation step or when-then to gate the work:
1import {2 createWorkflow,3 createStep,4 WorkflowResponse,5} from "@medusajs/framework/workflows-sdk"6 7const validateStep = createStep("validate", (input) => {8 if (!input.foo) {9 throw new Error("invalid")10 }11})12 13createWorkflow("my-workflow", (input) => {14 validateStep(input)15 16 return new WorkflowResponse(input)17})
Why it's Important#
is only meant for data transformation. Use a validation step or to gate the work instead.
Learn more in the Workflows documentation.
Fixable#
This rule isn't auto-fixable.
Was this page helpful?