Skip to content

Commit 065d933

Browse files
Ensure onError failures do not mask trigger option/task errors
Co-authored-by: Eric Allam <eric@trigger.dev>
1 parent 2236e0f commit 065d933

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

packages/ai/src/chatTransport.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,30 @@ describe("TriggerChatTransport", function () {
944944
expect(errors[0]?.error.message).toBe("string trigger options failure");
945945
});
946946

947+
it("keeps original trigger options failure when onError callback also fails", async function () {
948+
const transport = new TriggerChatTransport({
949+
task: "chat-task",
950+
stream: "chat-stream",
951+
accessToken: "pk_trigger",
952+
triggerOptions: async function triggerOptions() {
953+
throw new Error("trigger options failed root");
954+
},
955+
onError: async function onError() {
956+
throw new Error("onError failed");
957+
},
958+
});
959+
960+
await expect(
961+
transport.sendMessages({
962+
trigger: "submit-message",
963+
chatId: "chat-trigger-options-onerror-failure",
964+
messageId: undefined,
965+
messages: [],
966+
abortSignal: undefined,
967+
})
968+
).rejects.toThrowError("trigger options failed root");
969+
});
970+
947971
it("reports trigger task request failures through onError", async function () {
948972
const errors: TriggerChatTransportError[] = [];
949973
const server = await startServer(function (_req, res) {
@@ -1025,6 +1049,31 @@ describe("TriggerChatTransport", function () {
10251049
expect(errors[0]?.error.message).toBe("string trigger task failure");
10261050
});
10271051

1052+
it("keeps original trigger task failure when onError callback also fails", async function () {
1053+
const transport = new TriggerChatTransport({
1054+
task: "chat-task",
1055+
stream: "chat-stream",
1056+
accessToken: "pk_trigger",
1057+
onError: async function onError() {
1058+
throw new Error("onError failed");
1059+
},
1060+
});
1061+
1062+
(transport as any).triggerTask = async function triggerTask() {
1063+
throw new Error("trigger task failed root");
1064+
};
1065+
1066+
await expect(
1067+
transport.sendMessages({
1068+
trigger: "submit-message",
1069+
chatId: "chat-trigger-task-onerror-failure",
1070+
messageId: undefined,
1071+
messages: [],
1072+
abortSignal: undefined,
1073+
})
1074+
).rejects.toThrowError("trigger task failed root");
1075+
});
1076+
10281077
it("supports creating transport with factory function", async function () {
10291078
let observedRunId: string | undefined;
10301079
let callbackCompleted = false;

0 commit comments

Comments
 (0)