Skip to content

Commit ac41bf8

Browse files
Revert "fix(workflow-block): revert change bubbling up error for workflow block" (#965)
* Revert "fix(workflow-block): revert change bubbling up error for workflow blo…" This reverts commit 9f0993e. * revert test changes
1 parent 2e8f051 commit ac41bf8

File tree

3 files changed

+37
-35
lines changed

3 files changed

+37
-35
lines changed

apps/sim/executor/handlers/workflow/workflow-handler.test.ts

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,9 @@ describe('WorkflowBlockHandler', () => {
111111
'parent-workflow-id_sub_child-workflow-id_workflow-block-1'
112112
)
113113

114-
const result = await handler.execute(mockBlock, inputs, mockContext)
115-
expect(result).toEqual({
116-
success: false,
117-
error:
118-
'Cyclic workflow dependency detected: parent-workflow-id_sub_child-workflow-id_workflow-block-1',
119-
childWorkflowName: 'child-workflow-id',
120-
})
114+
await expect(handler.execute(mockBlock, inputs, mockContext)).rejects.toThrow(
115+
'Error in child workflow "child-workflow-id": Cyclic workflow dependency detected: parent-workflow-id_sub_child-workflow-id_workflow-block-1'
116+
)
121117
})
122118

123119
it('should enforce maximum depth limit', async () => {
@@ -130,12 +126,9 @@ describe('WorkflowBlockHandler', () => {
130126
'level1_sub_level2_sub_level3_sub_level4_sub_level5_sub_level6_sub_level7_sub_level8_sub_level9_sub_level10_sub_level11',
131127
}
132128

133-
const result = await handler.execute(mockBlock, inputs, deepContext)
134-
expect(result).toEqual({
135-
success: false,
136-
error: 'Maximum workflow nesting depth of 10 exceeded',
137-
childWorkflowName: 'child-workflow-id',
138-
})
129+
await expect(handler.execute(mockBlock, inputs, deepContext)).rejects.toThrow(
130+
'Error in child workflow "child-workflow-id": Maximum workflow nesting depth of 10 exceeded'
131+
)
139132
})
140133

141134
it('should handle child workflow not found', async () => {
@@ -147,25 +140,19 @@ describe('WorkflowBlockHandler', () => {
147140
statusText: 'Not Found',
148141
})
149142

150-
const result = await handler.execute(mockBlock, inputs, mockContext)
151-
expect(result).toEqual({
152-
success: false,
153-
error: 'Child workflow non-existent-workflow not found',
154-
childWorkflowName: 'non-existent-workflow',
155-
})
143+
await expect(handler.execute(mockBlock, inputs, mockContext)).rejects.toThrow(
144+
'Error in child workflow "non-existent-workflow": Child workflow non-existent-workflow not found'
145+
)
156146
})
157147

158148
it('should handle fetch errors gracefully', async () => {
159149
const inputs = { workflowId: 'child-workflow-id' }
160150

161151
mockFetch.mockRejectedValueOnce(new Error('Network error'))
162152

163-
const result = await handler.execute(mockBlock, inputs, mockContext)
164-
expect(result).toEqual({
165-
success: false,
166-
error: 'Child workflow child-workflow-id not found',
167-
childWorkflowName: 'child-workflow-id',
168-
})
153+
await expect(handler.execute(mockBlock, inputs, mockContext)).rejects.toThrow(
154+
'Error in child workflow "child-workflow-id": Child workflow child-workflow-id not found'
155+
)
169156
})
170157
})
171158

apps/sim/executor/handlers/workflow/workflow-handler.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ export class WorkflowBlockHandler implements BlockHandler {
115115
duration
116116
)
117117

118+
// If the child workflow failed, throw an error to trigger proper error handling in the parent
119+
if ((mappedResult as any).success === false) {
120+
const childError = (mappedResult as any).error || 'Unknown error'
121+
throw new Error(`Error in child workflow "${childWorkflowName}": ${childError}`)
122+
}
123+
118124
return mappedResult
119125
} catch (error: any) {
120126
logger.error(`Error executing child workflow ${workflowId}:`, error)
@@ -128,11 +134,15 @@ export class WorkflowBlockHandler implements BlockHandler {
128134
const workflowMetadata = workflows[workflowId]
129135
const childWorkflowName = workflowMetadata?.name || workflowId
130136

131-
return {
132-
success: false,
133-
error: error?.message || 'Child workflow execution failed',
134-
childWorkflowName,
135-
} as Record<string, any>
137+
// Enhance error message with child workflow context
138+
const originalError = error.message || 'Unknown error'
139+
140+
// Check if error message already has child workflow context to avoid duplication
141+
if (originalError.startsWith('Error in child workflow')) {
142+
throw error // Re-throw as-is to avoid duplication
143+
}
144+
145+
throw new Error(`Error in child workflow "${childWorkflowName}": ${originalError}`)
136146
}
137147
}
138148

apps/sim/executor/index.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ describe('Executor', () => {
14481448
}
14491449
)
14501450

1451-
it.concurrent('should surface child workflow failure in result without throwing', async () => {
1451+
it.concurrent('should propagate errors from child workflows to parent workflow', async () => {
14521452
const workflow = {
14531453
version: '1.0',
14541454
blocks: [
@@ -1488,12 +1488,17 @@ describe('Executor', () => {
14881488

14891489
const result = await executor.execute('test-workflow-id')
14901490

1491-
// Verify that child workflow failure is surfaced in the overall result
1491+
// Verify that child workflow errors propagate to parent
14921492
expect(result).toBeDefined()
14931493
if ('success' in result) {
1494-
// With reverted behavior, parent execution may still be considered successful overall,
1495-
// but the workflow block output should capture the failure. Only assert structure here.
1496-
expect(typeof result.success).toBe('boolean')
1494+
// The workflow should fail due to child workflow failure
1495+
expect(result.success).toBe(false)
1496+
expect(result.error).toBeDefined()
1497+
1498+
// Error message should indicate it came from a child workflow
1499+
if (result.error && typeof result.error === 'string') {
1500+
expect(result.error).toContain('Error in child workflow')
1501+
}
14971502
}
14981503
})
14991504
})

0 commit comments

Comments
 (0)