Skip to content

Commit 90198de

Browse files
Preserve thrown string when stream subscribe onError callback fails
Co-authored-by: Eric Allam <eric@trigger.dev>
1 parent 0323712 commit 90198de

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

packages/ai/src/chatTransport.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,54 @@ describe("TriggerChatTransport", function () {
12591259
expect(runStore.get("chat-stream-subscribe-onerror-failure")).toBeUndefined();
12601260
});
12611261

1262+
it(
1263+
"keeps original non-Error stream subscription failure when onError callback also fails",
1264+
async function () {
1265+
const runStore = new InMemoryTriggerChatRunStore();
1266+
1267+
const server = await startServer(function (req, res) {
1268+
if (req.method === "POST" && req.url === "/api/v1/tasks/chat-task/trigger") {
1269+
res.writeHead(200, {
1270+
"content-type": "application/json",
1271+
"x-trigger-jwt": "pk_stream_subscribe_string_onerror_failure",
1272+
});
1273+
res.end(JSON.stringify({ id: "run_stream_subscribe_string_onerror_failure" }));
1274+
return;
1275+
}
1276+
1277+
res.writeHead(404);
1278+
res.end();
1279+
});
1280+
1281+
const transport = new TriggerChatTransport({
1282+
task: "chat-task",
1283+
stream: "chat-stream",
1284+
accessToken: "pk_trigger",
1285+
baseURL: server.url,
1286+
runStore,
1287+
onError: async function onError() {
1288+
throw new Error("onError failed");
1289+
},
1290+
});
1291+
1292+
(transport as any).fetchRunStream = async function fetchRunStream() {
1293+
throw "stream subscribe string root";
1294+
};
1295+
1296+
await expect(
1297+
transport.sendMessages({
1298+
trigger: "submit-message",
1299+
chatId: "chat-stream-subscribe-string-onerror-failure",
1300+
messageId: undefined,
1301+
messages: [],
1302+
abortSignal: undefined,
1303+
})
1304+
).rejects.toBe("stream subscribe string root");
1305+
1306+
expect(runStore.get("chat-stream-subscribe-string-onerror-failure")).toBeUndefined();
1307+
}
1308+
);
1309+
12621310
it("cleans up async run-store state when stream subscription fails", async function () {
12631311
const runStore = new AsyncTrackedRunStore();
12641312

0 commit comments

Comments
 (0)