Skip to content

Commit 2236e0f

Browse files
Ensure onError failures never mask mapper errors
Co-authored-by: Eric Allam <eric@trigger.dev>
1 parent 1c50671 commit 2236e0f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

packages/ai/src/chatTransport.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,33 @@ describe("TriggerChatTransport", function () {
835835
expect(errors[0]?.error.message).toBe("string mapper failure");
836836
});
837837

838+
it("keeps original mapper failure when onError callback also fails", async function () {
839+
const transport = new TriggerChatTransport<
840+
UIMessage,
841+
{ prompt: string }
842+
>({
843+
task: "chat-task",
844+
stream: "chat-stream",
845+
accessToken: "pk_trigger",
846+
payloadMapper: async function payloadMapper() {
847+
throw new Error("mapper failed root");
848+
},
849+
onError: async function onError() {
850+
throw new Error("onError failed");
851+
},
852+
});
853+
854+
await expect(
855+
transport.sendMessages({
856+
trigger: "submit-message",
857+
chatId: "chat-mapper-onerror-failure",
858+
messageId: undefined,
859+
messages: [],
860+
abortSignal: undefined,
861+
})
862+
).rejects.toThrowError("mapper failed root");
863+
});
864+
838865
it("surfaces trigger options resolver errors and does not trigger runs", async function () {
839866
let triggerCalls = 0;
840867
const errors: TriggerChatTransportError[] = [];

0 commit comments

Comments
 (0)