Skip to content

Commit 16a1edb

Browse files
committed
Add taskId and runId to SubtaskUnwrapError
1 parent 181866b commit 16a1edb

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

packages/trigger-sdk/src/v3/shared.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,20 @@ export type TaskRunResult<TOutput = any> =
264264
};
265265

266266
export class SubtaskUnwrapError extends Error {
267-
constructor(taskId: string, subtaskError: unknown) {
267+
public readonly taskId: string;
268+
public readonly runId: string;
269+
270+
constructor(taskId: string, runId: string, subtaskError: unknown) {
268271
if (subtaskError instanceof Error) {
269272
super(`Error in ${taskId}: ${subtaskError.message}`, { cause: subtaskError });
270273
this.name = "SubtaskUnwrapError";
271274
} else {
272275
super(`Error in ${taskId}`, { cause: subtaskError });
273276
this.name = "SubtaskUnwrapError";
274277
}
278+
279+
this.taskId = taskId;
280+
this.runId = runId;
275281
}
276282
}
277283

@@ -291,7 +297,7 @@ export class TaskRunPromise<T> extends Promise<TaskRunResult<T>> {
291297
if (result.ok) {
292298
return result.output;
293299
} else {
294-
throw new SubtaskUnwrapError(this.taskId, result.error);
300+
throw new SubtaskUnwrapError(this.taskId, result.id, result.error);
295301
}
296302
});
297303
}

references/v3-catalog/src/trigger/simple.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@ export const fetchPostTask = task({
3131
export const anyPayloadTask = task({
3232
id: "any-payload-task",
3333
run: async (payload: any) => {
34-
const { url, method } = await tasks
35-
.triggerAndWait<typeof fetchPostTask>("fetch-post-task", {
36-
url: "https://jsonplaceholder.typicode.comasdqdasd/posts/1",
37-
})
38-
.unwrap();
39-
40-
console.log("Result from fetch-post-task 211111sss", { output: { url, method } });
34+
try {
35+
const { url, method } = await tasks
36+
.triggerAndWait<typeof fetchPostTask>("fetch-post-task", {
37+
url: "https://jsonplaceholder.typicode.comasdqdasd/posts/1",
38+
})
39+
.unwrap();
40+
41+
console.log("Result from fetch-post-task 211111sss", { output: { url, method } });
42+
} catch (error) {
43+
console.error("Error in fetch-post-task", { error });
44+
}
4145

4246
return {
4347
payload,

0 commit comments

Comments
 (0)