Skip to content

Commit b76c8b5

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

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

packages/ai/src/chatTransport.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,47 @@ describe("TriggerChatTransport", function () {
13011301
expect(runStore.get("chat-reconnect-error")).toBeUndefined();
13021302
});
13031303

1304+
it("normalizes non-Error reconnect failures before reporting onError", async function () {
1305+
const errors: TriggerChatTransportError[] = [];
1306+
const runStore = new InMemoryTriggerChatRunStore();
1307+
runStore.set({
1308+
chatId: "chat-reconnect-string-failure",
1309+
runId: "run_reconnect_string_failure",
1310+
publicAccessToken: "pk_reconnect_string_failure",
1311+
streamKey: "chat-stream",
1312+
lastEventId: "100-0",
1313+
isActive: true,
1314+
});
1315+
1316+
const transport = new TriggerChatTransport({
1317+
task: "chat-task",
1318+
stream: "chat-stream",
1319+
accessToken: "pk_trigger",
1320+
runStore,
1321+
onError: function onError(error) {
1322+
errors.push(error);
1323+
},
1324+
});
1325+
1326+
(transport as any).fetchRunStream = async function fetchRunStream() {
1327+
throw "reconnect string failure";
1328+
};
1329+
1330+
const stream = await transport.reconnectToStream({
1331+
chatId: "chat-reconnect-string-failure",
1332+
});
1333+
1334+
expect(stream).toBeNull();
1335+
expect(errors).toHaveLength(1);
1336+
expect(errors[0]).toMatchObject({
1337+
phase: "reconnect",
1338+
chatId: "chat-reconnect-string-failure",
1339+
runId: "run_reconnect_string_failure",
1340+
});
1341+
expect(errors[0]?.error.message).toBe("reconnect string failure");
1342+
expect(runStore.get("chat-reconnect-string-failure")).toBeUndefined();
1343+
});
1344+
13041345
it("cleans run store state when stream completes", async function () {
13051346
const trackedRunStore = new TrackedRunStore();
13061347

0 commit comments

Comments
 (0)