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:

src/workflows/example.ts
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:

src/workflows/example.ts
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#

transform is only meant for data transformation. Use a validation step or when-then to gate the work instead.

Learn more in the Workflows documentation.

Fixable#

This rule isn't auto-fixable.

Was this page helpful?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Docs MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break
⇧↵