Skip to content

Commit 56835b9

Browse files
authored
fix(executor): duplicate error, cmd+enter (#1920)
* Fix executor error * Fix cmd+enter * Lint
1 parent 9a6a6fd commit 56835b9

File tree

4 files changed

+52
-32
lines changed

4 files changed

+52
-32
lines changed

apps/sim/app/api/workflows/[id]/execute/route.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,10 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
510510

511511
return NextResponse.json(filteredResult)
512512
} catch (error: any) {
513-
logger.error(`[${requestId}] Non-SSE execution failed:`, error)
513+
// Block errors are already logged with full details by BlockExecutor
514+
// Only log the error message here to avoid duplicate logging
515+
const errorMessage = error.message || 'Unknown error'
516+
logger.error(`[${requestId}] Non-SSE execution failed: ${errorMessage}`)
514517

515518
const executionResult = error.executionResult
516519

@@ -803,7 +806,10 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
803806
},
804807
})
805808
} catch (error: any) {
806-
logger.error(`[${requestId}] SSE execution failed:`, error)
809+
// Block errors are already logged with full details by BlockExecutor
810+
// Only log the error message here to avoid duplicate logging
811+
const errorMessage = error.message || 'Unknown error'
812+
logger.error(`[${requestId}] SSE execution failed: ${errorMessage}`)
807813

808814
const executionResult = error.executionResult
809815

@@ -813,7 +819,7 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
813819
executionId,
814820
workflowId,
815821
data: {
816-
error: executionResult?.error || error.message || 'Unknown error',
822+
error: executionResult?.error || errorMessage,
817823
duration: executionResult?.metadata?.duration || 0,
818824
},
819825
})

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/panel-new.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,11 @@ export function Panel() {
244244
shortcut: 'Mod+Enter',
245245
allowInEditable: false,
246246
handler: () => {
247-
try {
248-
if (isExecuting) {
249-
cancelWorkflow()
250-
} else if (!isButtonDisabled) {
251-
runWorkflow()
252-
} else {
253-
logger.warn('Cannot run workflow: button is disabled')
254-
}
255-
} catch (err) {
256-
logger.error('Failed to execute Cmd+Enter command', { err })
247+
// Do exactly what the Run button does
248+
if (isExecuting) {
249+
cancelWorkflow()
250+
} else {
251+
runWorkflow()
257252
}
258253
},
259254
},

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

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { WorkflowValidationError } from '@/serializer'
1616
import { useExecutionStore } from '@/stores/execution/store'
1717
import { useVariablesStore } from '@/stores/panel/variables/store'
1818
import { useEnvironmentStore } from '@/stores/settings/environment/store'
19-
import { useTerminalConsoleStore } from '@/stores/terminal'
19+
import { type ConsoleEntry, useTerminalConsoleStore } from '@/stores/terminal'
2020
import { useWorkflowDiffStore } from '@/stores/workflow-diff'
2121
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
2222
import { mergeSubblockState } from '@/stores/workflows/utils'
@@ -1005,21 +1005,31 @@ export function useWorkflowExecution() {
10051005
logs: [],
10061006
}
10071007

1008-
// Add error to console
1009-
addConsole({
1010-
input: {},
1011-
output: {},
1012-
success: false,
1013-
error: data.error,
1014-
durationMs: data.duration || 0,
1015-
startedAt: new Date(Date.now() - (data.duration || 0)).toISOString(),
1016-
endedAt: new Date().toISOString(),
1017-
workflowId: activeWorkflowId,
1018-
blockId: 'workflow',
1019-
executionId: executionId || uuidv4(),
1020-
blockName: 'Workflow Execution',
1021-
blockType: 'workflow',
1022-
})
1008+
// Only add workflow-level error if no blocks have executed yet
1009+
// This catches pre-execution errors (validation, serialization, etc.)
1010+
// Block execution errors are already logged via onBlockError callback
1011+
const { entries } = useTerminalConsoleStore.getState()
1012+
const existingLogs = entries.filter(
1013+
(log: ConsoleEntry) => log.executionId === executionId
1014+
)
1015+
1016+
if (existingLogs.length === 0) {
1017+
// No blocks executed yet - this is a pre-execution error
1018+
addConsole({
1019+
input: {},
1020+
output: {},
1021+
success: false,
1022+
error: data.error,
1023+
durationMs: data.duration || 0,
1024+
startedAt: new Date(Date.now() - (data.duration || 0)).toISOString(),
1025+
endedAt: new Date().toISOString(),
1026+
workflowId: activeWorkflowId,
1027+
blockId: 'validation',
1028+
executionId: executionId || uuidv4(),
1029+
blockName: 'Workflow Validation',
1030+
blockType: 'validation',
1031+
})
1032+
}
10231033
},
10241034
},
10251035
})

apps/sim/executor/execution/engine.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,13 @@ export class ExecutionEngine {
7272
logs: this.context.blockLogs,
7373
metadata: this.context.metadata,
7474
}
75-
const executionError = new Error(errorMessage)
76-
;(executionError as any).executionResult = executionResult
77-
throw executionError
75+
76+
// Attach executionResult to the original error instead of creating a new one
77+
// This preserves block error metadata (blockId, blockName, blockType, etc.)
78+
if (error && typeof error === 'object') {
79+
;(error as any).executionResult = executionResult
80+
}
81+
throw error
7882
}
7983
}
8084

@@ -105,6 +109,11 @@ export class ExecutionEngine {
105109

106110
private trackExecution(promise: Promise<void>): void {
107111
this.executing.add(promise)
112+
// Attach error handler to prevent unhandled rejection warnings
113+
// The actual error handling happens in waitForAllExecutions/waitForAnyExecution
114+
promise.catch(() => {
115+
// Error will be properly handled by Promise.all/Promise.race in wait methods
116+
})
108117
promise.finally(() => {
109118
this.executing.delete(promise)
110119
})

0 commit comments

Comments
 (0)