diff --git a/packages/core/src/v3/types/tasks.ts b/packages/core/src/v3/types/tasks.ts index 8c1e4d1014..53044c2f5e 100644 --- a/packages/core/src/v3/types/tasks.ts +++ b/packages/core/src/v3/types/tasks.ts @@ -149,11 +149,7 @@ export type HandleErrorArgs = { signal?: AbortSignal; }; -export type HandleErrorFunction = ( - payload: any, - error: unknown, - params: HandleErrorArgs -) => HandleErrorResult; +export type HandleErrorFunction = AnyOnCatchErrorHookFunction; type CommonTaskOptions< TIdentifier extends string, diff --git a/packages/core/src/v3/workers/taskExecutor.ts b/packages/core/src/v3/workers/taskExecutor.ts index ce7a9f8246..6fbc207dcc 100644 --- a/packages/core/src/v3/workers/taskExecutor.ts +++ b/packages/core/src/v3/workers/taskExecutor.ts @@ -1036,11 +1036,17 @@ export class TaskExecutor { return { status: "skipped" }; } + const taskCatchErrorHook = lifecycleHooks.getTaskCatchErrorHook(this.task.id); + const globalCatchErrorHooks = lifecycleHooks.getGlobalCatchErrorHooks(); + + if (globalCatchErrorHooks.length === 0 && !taskCatchErrorHook) { + return { status: "noop" }; + } + return this._tracer.startActiveSpan( "catchError", async (span) => { // Try task-specific catch error hook first - const taskCatchErrorHook = lifecycleHooks.getTaskCatchErrorHook(this.task.id); if (taskCatchErrorHook) { const result = await taskCatchErrorHook({ payload, @@ -1060,7 +1066,6 @@ export class TaskExecutor { } // Try global catch error hooks in order - const globalCatchErrorHooks = lifecycleHooks.getGlobalCatchErrorHooks(); for (const hook of globalCatchErrorHooks) { const result = await hook.fn({ payload,