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
import {
  createWorkflow,
  transform,
  WorkflowResponse,
} from "@medusajs/framework/workflows-sdk"

createWorkflow("my-workflow", (input) => {
  const value = transform({ input }, (data) => {
    if (!data.input.foo) {
      throw new Error("invalid")
    }
    return data.input.foo
  })

  return new WorkflowResponse(value)
})

Instead, use a validation step or when-then to gate the work:

src/workflows/example.ts
import {
  createWorkflow,
  createStep,
  WorkflowResponse,
} from "@medusajs/framework/workflows-sdk"

const validateStep = createStep("validate", (input) => {
  if (!input.foo) {
    throw new Error("invalid")
  }
})

createWorkflow("my-workflow", (input) => {
  validateStep(input)

  return new WorkflowResponse(input)
})

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
⇧↵