Skip to content

v4: Fix HandleErrorFunction type #1829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions packages/core/src/v3/types/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/v3/workers/taskExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down