Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code 32b1c6abe6 Missing null guard on steps in multiple callers of getStepDefinitionOrThrow
https://sonarly.com/issue/4204?type=bug

Multiple React components call `getStepDefinitionOrThrow()` with `steps: null` for non-trigger step IDs, causing an unhandled throw that crashes the component tree when the workflow version has no steps defined.

Fix: The fix modifies `getStepDefinitionOrThrow` to return `undefined` instead of throwing when `steps` is `null` and the `stepId` is not a trigger step. Since `WorkflowVersion.steps` is legitimately `null` (a valid state when a version has no steps), throwing an uncaught error in this function during a React render path causes a full component-tree crash.

**Before:**
```typescript file=packages/twenty-front/src/modules/workflow/utils/getStepDefinitionOrThrow.ts lines=32-36
  if (!isDefined(steps)) {
    throw new Error(
      'Malformed workflow version: missing steps information; be sure to create at least one step before trying to edit one',
    );
  }
```

**After:**
```typescript file=packages/twenty-front/src/modules/workflow/utils/getStepDefinitionOrThrow.ts lines=32-34
  if (!isDefined(steps)) {
    return undefined;
  }
```

All five affected callers (`WorkflowStepDetail`, `WorkflowRunStepNodeDetail`, `WorkflowRunStepOutputDetail`, `WorkflowIteratorSubStepSwitcher`, `CommandMenuWorkflowRunViewStepContent`) already handle `undefined` from this function via `!isDefined(stepDefinition)` guards or optional chaining, so they gracefully render `null` instead of crashing. This is consistent with the `stepSelector` pattern already in the codebase and mirrors the guard that `CommandMenuWorkflowStepInfo` applies before calling this function.
2026-03-03 08:39:24 +00:00
@@ -30,9 +30,7 @@ export const getStepDefinitionOrThrow = ({
}
if (!isDefined(steps)) {
throw new Error(
'Malformed workflow version: missing steps information; be sure to create at least one step before trying to edit one',
);
return undefined;
}
const selectedNodePosition = findStepPosition({