Skip to content

Commit eb767b5

Browse files
committed
remove more dead code
1 parent 594bcac commit eb767b5

File tree

5 files changed

+19
-24
lines changed

5 files changed

+19
-24
lines changed

apps/sim/background/schedule-execution.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
} from '@/lib/workflows/schedules/utils'
2222
import { ExecutionSnapshot } from '@/executor/execution/snapshot'
2323
import type { ExecutionMetadata } from '@/executor/execution/types'
24-
import type { ExecutionResult } from '@/executor/types'
24+
import { hasExecutionResult } from '@/executor/utils/errors'
2525
import { MAX_CONSECUTIVE_FAILURES } from '@/triggers/constants'
2626

2727
const logger = createLogger('TriggerScheduleExecution')
@@ -231,8 +231,7 @@ async function runWorkflowExecution({
231231
} catch (error: unknown) {
232232
logger.error(`[${requestId}] Early failure in scheduled workflow ${payload.workflowId}`, error)
233233

234-
const errorWithResult = error as { executionResult?: ExecutionResult }
235-
const executionResult = errorWithResult?.executionResult
234+
const executionResult = hasExecutionResult(error) ? error.executionResult : undefined
236235
const { traceSpans } = executionResult ? buildTraceSpans(executionResult) : { traceSpans: [] }
237236

238237
await loggingSession.safeCompleteWithError({

apps/sim/background/webhook-execution.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { loadDeployedWorkflowState } from '@/lib/workflows/persistence/utils'
1616
import { getWorkflowById } from '@/lib/workflows/utils'
1717
import { ExecutionSnapshot } from '@/executor/execution/snapshot'
1818
import type { ExecutionMetadata } from '@/executor/execution/types'
19-
import type { ExecutionResult } from '@/executor/types'
19+
import { hasExecutionResult } from '@/executor/utils/errors'
2020
import { safeAssign } from '@/tools/safe-assign'
2121
import { getTrigger, isTriggerValid } from '@/triggers'
2222

@@ -578,12 +578,13 @@ async function executeWebhookJobInternal(
578578
deploymentVersionId,
579579
})
580580

581-
const errorWithResult = error as { executionResult?: ExecutionResult }
582-
const executionResult = errorWithResult?.executionResult || {
583-
success: false,
584-
output: {},
585-
logs: [],
586-
}
581+
const executionResult = hasExecutionResult(error)
582+
? error.executionResult
583+
: {
584+
success: false,
585+
output: {},
586+
logs: [],
587+
}
587588
const { traceSpans } = buildTraceSpans(executionResult)
588589

589590
await loggingSession.safeCompleteWithError({

apps/sim/background/workflow-execution.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { PauseResumeManager } from '@/lib/workflows/executor/human-in-the-loop-m
99
import { getWorkflowById } from '@/lib/workflows/utils'
1010
import { ExecutionSnapshot } from '@/executor/execution/snapshot'
1111
import type { ExecutionMetadata } from '@/executor/execution/types'
12-
import type { ExecutionResult } from '@/executor/types'
12+
import { hasExecutionResult } from '@/executor/utils/errors'
1313
import type { CoreTriggerType } from '@/stores/logs/filters/types'
1414

1515
const logger = createLogger('TriggerWorkflowExecution')
@@ -160,8 +160,7 @@ export async function executeWorkflowJob(payload: WorkflowExecutionPayload) {
160160
executionId,
161161
})
162162

163-
const errorWithResult = error as { executionResult?: ExecutionResult }
164-
const executionResult = errorWithResult?.executionResult
163+
const executionResult = hasExecutionResult(error) ? error.executionResult : undefined
165164
const { traceSpans } = executionResult ? buildTraceSpans(executionResult) : { traceSpans: [] }
166165

167166
await loggingSession.safeCompleteWithError({

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ export class WorkflowBlockHandler implements BlockHandler {
139139
)
140140

141141
return mappedResult
142-
} catch (error: any) {
142+
} catch (error: unknown) {
143143
logger.error(`Error executing child workflow ${workflowId}:`, error)
144144

145145
const { workflows } = useWorkflowRegistry.getState()
146146
const workflowMetadata = workflows[workflowId]
147147
const childWorkflowName = workflowMetadata?.name || workflowId
148148

149-
const originalError = error.message || 'Unknown error'
149+
const originalError = error instanceof Error ? error.message : 'Unknown error'
150150
let childTraceSpans: WorkflowTraceSpan[] = []
151151
let executionResult: ExecutionResult | undefined
152152

@@ -170,7 +170,7 @@ export class WorkflowBlockHandler implements BlockHandler {
170170
childWorkflowName,
171171
childTraceSpans,
172172
executionResult,
173-
cause: error,
173+
cause: error instanceof Error ? error : undefined,
174174
})
175175
}
176176
}

apps/sim/lib/workflows/executor/execution-core.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type {
2424
IterationContext,
2525
} from '@/executor/execution/types'
2626
import type { ExecutionResult, NormalizedBlockOutput } from '@/executor/types'
27+
import { hasExecutionResult } from '@/executor/utils/errors'
2728
import { Serializer } from '@/serializer'
2829
import { mergeSubblockState } from '@/stores/workflows/server-utils'
2930

@@ -383,20 +384,15 @@ export async function executeWorkflowCore(
383384
} catch (error: unknown) {
384385
logger.error(`[${requestId}] Execution failed:`, error)
385386

386-
const errorWithResult = error as {
387-
executionResult?: ExecutionResult
388-
message?: string
389-
stack?: string
390-
}
391-
const executionResult = errorWithResult?.executionResult
387+
const executionResult = hasExecutionResult(error) ? error.executionResult : undefined
392388
const { traceSpans } = executionResult ? buildTraceSpans(executionResult) : { traceSpans: [] }
393389

394390
await loggingSession.safeCompleteWithError({
395391
endedAt: new Date().toISOString(),
396392
totalDurationMs: executionResult?.metadata?.duration || 0,
397393
error: {
398-
message: errorWithResult?.message || 'Execution failed',
399-
stackTrace: errorWithResult?.stack,
394+
message: error instanceof Error ? error.message : 'Execution failed',
395+
stackTrace: error instanceof Error ? error.stack : undefined,
400396
},
401397
traceSpans,
402398
})

0 commit comments

Comments
 (0)