Skip to content

Commit a7cba36

Browse files
Cover non-Error trigger option failures in onError reporting
Co-authored-by: Eric Allam <eric@trigger.dev>
1 parent d0b3119 commit a7cba36

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

packages/ai/src/chatTransport.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,40 @@ describe("TriggerChatTransport", function () {
883883
expect(errors[0]?.error.message).toBe("trigger options failed");
884884
});
885885

886+
it("normalizes non-Error trigger options failures before reporting onError", async function () {
887+
const errors: TriggerChatTransportError[] = [];
888+
889+
const transport = new TriggerChatTransport({
890+
task: "chat-task",
891+
stream: "chat-stream",
892+
accessToken: "pk_trigger",
893+
triggerOptions: async function triggerOptions() {
894+
throw "string trigger options failure";
895+
},
896+
onError: function onError(error) {
897+
errors.push(error);
898+
},
899+
});
900+
901+
await expect(
902+
transport.sendMessages({
903+
trigger: "submit-message",
904+
chatId: "chat-trigger-string-failure",
905+
messageId: undefined,
906+
messages: [],
907+
abortSignal: undefined,
908+
})
909+
).rejects.toBe("string trigger options failure");
910+
911+
expect(errors).toHaveLength(1);
912+
expect(errors[0]).toMatchObject({
913+
phase: "triggerOptions",
914+
chatId: "chat-trigger-string-failure",
915+
runId: undefined,
916+
});
917+
expect(errors[0]?.error.message).toBe("string trigger options failure");
918+
});
919+
886920
it("reports trigger task request failures through onError", async function () {
887921
const errors: TriggerChatTransportError[] = [];
888922
const server = await startServer(function (_req, res) {

0 commit comments

Comments
 (0)