From eb767b5edea67336b003e594c9ee3edc504b595c Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Sat, 24 Jan 2026 01:58:02 -0800 Subject: [PATCH] remove more dead code --- apps/sim/background/schedule-execution.ts | 5 ++--- apps/sim/background/webhook-execution.ts | 15 ++++++++------- apps/sim/background/workflow-execution.ts | 5 ++--- .../handlers/workflow/workflow-handler.ts | 6 +++--- apps/sim/lib/workflows/executor/execution-core.ts | 12 ++++-------- 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/apps/sim/background/schedule-execution.ts b/apps/sim/background/schedule-execution.ts index 54ce24e5e..c52676b8d 100644 --- a/apps/sim/background/schedule-execution.ts +++ b/apps/sim/background/schedule-execution.ts @@ -21,7 +21,7 @@ import { } from '@/lib/workflows/schedules/utils' import { ExecutionSnapshot } from '@/executor/execution/snapshot' import type { ExecutionMetadata } from '@/executor/execution/types' -import type { ExecutionResult } from '@/executor/types' +import { hasExecutionResult } from '@/executor/utils/errors' import { MAX_CONSECUTIVE_FAILURES } from '@/triggers/constants' const logger = createLogger('TriggerScheduleExecution') @@ -231,8 +231,7 @@ async function runWorkflowExecution({ } catch (error: unknown) { logger.error(`[${requestId}] Early failure in scheduled workflow ${payload.workflowId}`, error) - const errorWithResult = error as { executionResult?: ExecutionResult } - const executionResult = errorWithResult?.executionResult + const executionResult = hasExecutionResult(error) ? error.executionResult : undefined const { traceSpans } = executionResult ? buildTraceSpans(executionResult) : { traceSpans: [] } await loggingSession.safeCompleteWithError({ diff --git a/apps/sim/background/webhook-execution.ts b/apps/sim/background/webhook-execution.ts index a32ce0902..e5e3d3007 100644 --- a/apps/sim/background/webhook-execution.ts +++ b/apps/sim/background/webhook-execution.ts @@ -16,7 +16,7 @@ import { loadDeployedWorkflowState } from '@/lib/workflows/persistence/utils' import { getWorkflowById } from '@/lib/workflows/utils' import { ExecutionSnapshot } from '@/executor/execution/snapshot' import type { ExecutionMetadata } from '@/executor/execution/types' -import type { ExecutionResult } from '@/executor/types' +import { hasExecutionResult } from '@/executor/utils/errors' import { safeAssign } from '@/tools/safe-assign' import { getTrigger, isTriggerValid } from '@/triggers' @@ -578,12 +578,13 @@ async function executeWebhookJobInternal( deploymentVersionId, }) - const errorWithResult = error as { executionResult?: ExecutionResult } - const executionResult = errorWithResult?.executionResult || { - success: false, - output: {}, - logs: [], - } + const executionResult = hasExecutionResult(error) + ? error.executionResult + : { + success: false, + output: {}, + logs: [], + } const { traceSpans } = buildTraceSpans(executionResult) await loggingSession.safeCompleteWithError({ diff --git a/apps/sim/background/workflow-execution.ts b/apps/sim/background/workflow-execution.ts index f7e061fbf..99e83d54c 100644 --- a/apps/sim/background/workflow-execution.ts +++ b/apps/sim/background/workflow-execution.ts @@ -9,7 +9,7 @@ import { PauseResumeManager } from '@/lib/workflows/executor/human-in-the-loop-m import { getWorkflowById } from '@/lib/workflows/utils' import { ExecutionSnapshot } from '@/executor/execution/snapshot' import type { ExecutionMetadata } from '@/executor/execution/types' -import type { ExecutionResult } from '@/executor/types' +import { hasExecutionResult } from '@/executor/utils/errors' import type { CoreTriggerType } from '@/stores/logs/filters/types' const logger = createLogger('TriggerWorkflowExecution') @@ -160,8 +160,7 @@ export async function executeWorkflowJob(payload: WorkflowExecutionPayload) { executionId, }) - const errorWithResult = error as { executionResult?: ExecutionResult } - const executionResult = errorWithResult?.executionResult + const executionResult = hasExecutionResult(error) ? error.executionResult : undefined const { traceSpans } = executionResult ? buildTraceSpans(executionResult) : { traceSpans: [] } await loggingSession.safeCompleteWithError({ diff --git a/apps/sim/executor/handlers/workflow/workflow-handler.ts b/apps/sim/executor/handlers/workflow/workflow-handler.ts index 6759af5ff..3ec7319eb 100644 --- a/apps/sim/executor/handlers/workflow/workflow-handler.ts +++ b/apps/sim/executor/handlers/workflow/workflow-handler.ts @@ -139,14 +139,14 @@ export class WorkflowBlockHandler implements BlockHandler { ) return mappedResult - } catch (error: any) { + } catch (error: unknown) { logger.error(`Error executing child workflow ${workflowId}:`, error) const { workflows } = useWorkflowRegistry.getState() const workflowMetadata = workflows[workflowId] const childWorkflowName = workflowMetadata?.name || workflowId - const originalError = error.message || 'Unknown error' + const originalError = error instanceof Error ? error.message : 'Unknown error' let childTraceSpans: WorkflowTraceSpan[] = [] let executionResult: ExecutionResult | undefined @@ -170,7 +170,7 @@ export class WorkflowBlockHandler implements BlockHandler { childWorkflowName, childTraceSpans, executionResult, - cause: error, + cause: error instanceof Error ? error : undefined, }) } } diff --git a/apps/sim/lib/workflows/executor/execution-core.ts b/apps/sim/lib/workflows/executor/execution-core.ts index d128d9e20..c2b300f08 100644 --- a/apps/sim/lib/workflows/executor/execution-core.ts +++ b/apps/sim/lib/workflows/executor/execution-core.ts @@ -24,6 +24,7 @@ import type { IterationContext, } from '@/executor/execution/types' import type { ExecutionResult, NormalizedBlockOutput } from '@/executor/types' +import { hasExecutionResult } from '@/executor/utils/errors' import { Serializer } from '@/serializer' import { mergeSubblockState } from '@/stores/workflows/server-utils' @@ -383,20 +384,15 @@ export async function executeWorkflowCore( } catch (error: unknown) { logger.error(`[${requestId}] Execution failed:`, error) - const errorWithResult = error as { - executionResult?: ExecutionResult - message?: string - stack?: string - } - const executionResult = errorWithResult?.executionResult + const executionResult = hasExecutionResult(error) ? error.executionResult : undefined const { traceSpans } = executionResult ? buildTraceSpans(executionResult) : { traceSpans: [] } await loggingSession.safeCompleteWithError({ endedAt: new Date().toISOString(), totalDurationMs: executionResult?.metadata?.duration || 0, error: { - message: errorWithResult?.message || 'Execution failed', - stackTrace: errorWithResult?.stack, + message: error instanceof Error ? error.message : 'Execution failed', + stackTrace: error instanceof Error ? error.stack : undefined, }, traceSpans, })