Skip to content

Commit 6caa79b

Browse files
author
Theodore Li
committed
fix(mothership): mothership-ran workflows show workflow validation errors
1 parent 3bd2750 commit 6caa79b

File tree

1 file changed

+57
-5
lines changed

1 file changed

+57
-5
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/utils/workflow-execution-utils.ts

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ export async function executeWorkflowWithFullLogging(
436436
}
437437

438438
const executionId = options.executionId || uuidv4()
439-
const { addConsole, updateConsole } = useTerminalConsoleStore.getState()
439+
const { addConsole, updateConsole, cancelRunningEntries } = useTerminalConsoleStore.getState()
440440
const { setActiveBlocks, setBlockRunStatus, setEdgeRunStatus, setCurrentExecutionId } =
441441
useExecutionStore.getState()
442442
const wfId = targetWorkflowId
@@ -445,6 +445,7 @@ export async function executeWorkflowWithFullLogging(
445445
const activeBlocksSet = new Set<string>()
446446
const activeBlockRefCounts = new Map<string, number>()
447447
const executionIdRef = { current: executionId }
448+
const accumulatedBlockLogs: BlockLog[] = []
448449

449450
const blockHandlers = createBlockEventHandlers(
450451
{
@@ -453,7 +454,7 @@ export async function executeWorkflowWithFullLogging(
453454
workflowEdges,
454455
activeBlocksSet,
455456
activeBlockRefCounts,
456-
accumulatedBlockLogs: [],
457+
accumulatedBlockLogs,
457458
accumulatedBlockStates: new Map(),
458459
executedBlockIds: new Set(),
459460
consoleMode: 'update',
@@ -490,7 +491,24 @@ export async function executeWorkflowWithFullLogging(
490491

491492
if (!response.ok) {
492493
const error = await response.json()
493-
throw new Error(error.error || 'Workflow execution failed')
494+
const errorMessage = error.error || 'Workflow execution failed'
495+
const now = new Date().toISOString()
496+
addConsole({
497+
input: {},
498+
output: {},
499+
success: false,
500+
error: errorMessage,
501+
durationMs: 0,
502+
startedAt: now,
503+
executionOrder: 0,
504+
endedAt: now,
505+
workflowId: wfId,
506+
blockId: 'execution-error',
507+
executionId,
508+
blockName: 'Execution Error',
509+
blockType: 'error',
510+
})
511+
throw new Error(errorMessage)
494512
}
495513

496514
if (!response.body) {
@@ -575,15 +593,49 @@ export async function executeWorkflowWithFullLogging(
575593
}
576594
break
577595

578-
case 'execution:error':
596+
case 'execution:error': {
579597
setCurrentExecutionId(wfId, null)
598+
const errorMessage = event.data.error || 'Execution failed'
580599
executionResult = {
581600
success: false,
582601
output: {},
583-
error: event.data.error || 'Execution failed',
602+
error: errorMessage,
584603
logs: [],
585604
}
605+
606+
cancelRunningEntries(wfId)
607+
608+
const isPreExecutionError = accumulatedBlockLogs.length === 0
609+
const hasBlockError = accumulatedBlockLogs.some((log) => log.error)
610+
if (isPreExecutionError || !hasBlockError) {
611+
const isTimeout = errorMessage.toLowerCase().includes('timed out')
612+
const now = new Date().toISOString()
613+
addConsole({
614+
input: {},
615+
output: {},
616+
success: false,
617+
error: errorMessage,
618+
durationMs: event.data.duration || 0,
619+
startedAt: now,
620+
executionOrder: isPreExecutionError ? 0 : Number.MAX_SAFE_INTEGER,
621+
endedAt: now,
622+
workflowId: wfId,
623+
blockId: isPreExecutionError
624+
? 'validation'
625+
: isTimeout
626+
? 'timeout-error'
627+
: 'execution-error',
628+
executionId: executionIdRef.current,
629+
blockName: isPreExecutionError
630+
? 'Workflow Validation'
631+
: isTimeout
632+
? 'Timeout Error'
633+
: 'Execution Error',
634+
blockType: isPreExecutionError ? 'validation' : 'error',
635+
})
636+
}
586637
break
638+
}
587639
}
588640
}
589641
}

0 commit comments

Comments
 (0)