@@ -4,6 +4,7 @@ import type { TraceSpan } from '@/lib/logs/types'
44import type { BlockOutput } from '@/blocks/types'
55import { Executor } from '@/executor'
66import { BlockType , DEFAULTS , HTTP } from '@/executor/constants'
7+ import { ChildWorkflowError } from '@/executor/errors/child-workflow-error'
78import type {
89 BlockHandler ,
910 ExecutionContext ,
@@ -145,31 +146,30 @@ export class WorkflowBlockHandler implements BlockHandler {
145146 const childWorkflowName = workflowMetadata ?. name || workflowId
146147
147148 const originalError = error . message || 'Unknown error'
148- const wrappedError = new Error (
149- `Error in child workflow "${ childWorkflowName } ": ${ originalError } `
150- )
151-
149+ let childTraceSpans : WorkflowTraceSpan [ ] = [ ]
150+ let executionResult : ExecutionResult | undefined
152151 if ( error . executionResult ?. logs ) {
153- const executionResult = error . executionResult as ExecutionResult
152+ executionResult = error . executionResult as ExecutionResult
154153
155154 logger . info ( `Extracting child trace spans from error.executionResult` , {
156155 hasLogs : ( executionResult . logs ?. length ?? 0 ) > 0 ,
157156 logCount : executionResult . logs ?. length ?? 0 ,
158157 } )
159158
160- const childTraceSpans = this . captureChildWorkflowLogs (
161- executionResult ,
162- childWorkflowName ,
163- ctx
164- )
159+ childTraceSpans = this . captureChildWorkflowLogs ( executionResult , childWorkflowName , ctx )
165160
166161 logger . info ( `Captured ${ childTraceSpans . length } child trace spans from failed execution` )
167- ; ( wrappedError as any ) . childTraceSpans = childTraceSpans
168162 } else if ( error . childTraceSpans && Array . isArray ( error . childTraceSpans ) ) {
169- ; ( wrappedError as any ) . childTraceSpans = error . childTraceSpans
163+ childTraceSpans = error . childTraceSpans
170164 }
171165
172- throw wrappedError
166+ throw new ChildWorkflowError ( {
167+ message : `Error in child workflow "${ childWorkflowName } ": ${ originalError } ` ,
168+ childWorkflowName,
169+ childTraceSpans,
170+ executionResult,
171+ cause : error ,
172+ } )
173173 }
174174 }
175175
@@ -441,11 +441,11 @@ export class WorkflowBlockHandler implements BlockHandler {
441441
442442 if ( ! success ) {
443443 logger . warn ( `Child workflow ${ childWorkflowName } failed` )
444- const error = new Error (
445- `Error in child workflow "${ childWorkflowName } ": ${ childResult . error || 'Child workflow execution failed' } `
446- )
447- ; ( error as any ) . childTraceSpans = childTraceSpans || [ ]
448- throw error
444+ throw new ChildWorkflowError ( {
445+ message : `Error in child workflow "${ childWorkflowName } ": ${ childResult . error || 'Child workflow execution failed' } ` ,
446+ childWorkflowName ,
447+ childTraceSpans : childTraceSpans || [ ] ,
448+ } )
449449 }
450450
451451 return {
0 commit comments