Surface reason-only websocket close diagnostics in renderer

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 06:54:44 +00:00
1 parent 273ac4bbb8
commit 30c19f0e71
2 files changed
+35 -2

No files matched your search

+27
View File
@@ -484,6 +484,19 @@ describe("wsNativeApi", () => {
await expect(request).rejects.toThrow("websocket disconnected (code 4201)");
});
it("includes generic close reason details when code is missing on disconnect", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4459");
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");
const api = getOrCreateWsNativeApi();
const request = api.todos.list();
const socket = MockWebSocket.instances[0];
await waitForCondition(() => (socket?.sentMessages.length ?? 0) > 0);
socket?.closeWith({ reason: "custom-reason-only" });
await expect(request).rejects.toThrow("websocket disconnected (reason: custom-reason-only)");
});
it("falls back to generic disconnect message when close code is missing", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4455");
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");
@@ -1138,6 +1151,20 @@ describe("wsNativeApi", () => {
);
});
it("reports generic close reason when websocket closes before opening without code", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4460");
MockWebSocket.failCloseBeforeOpen = true;
MockWebSocket.failCloseBeforeOpenEvent = {
reason: "custom-reason-only",
};
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");
const api = getOrCreateWsNativeApi();
await expect(api.todos.list()).rejects.toThrow(
"Failed to connect to local t3 runtime (close reason: custom-reason-only).",
);
});
it("falls back to generic connect failure when close metadata is missing", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4456");
MockWebSocket.failCloseBeforeOpen = true;
+8 -2
View File
@@ -48,9 +48,12 @@ function runtimeConnectErrorFromClose(event: unknown) {
"Failed to connect to local t3 runtime: replaced by a newer websocket client.",
);
}
if (code === null) {
if (code === null && (!reason || reason.length === 0)) {
return new Error("Failed to connect to local t3 runtime.");
}
if (code === null) {
return new Error(`Failed to connect to local t3 runtime (close reason: ${reason}).`);
}
if (!reason || reason.length === 0) {
return new Error(`Failed to connect to local t3 runtime (close code ${code}).`);
}
@@ -68,9 +71,12 @@ function requestDisconnectError(id: string, event: unknown) {
) {
return new Error(`Request ${id} failed: websocket disconnected (replaced-by-new-client).`);
}
if (code === null) {
if (code === null && (!reason || reason.length === 0)) {
return new Error(`Request ${id} failed: websocket disconnected.`);
}
if (code === null) {
return new Error(`Request ${id} failed: websocket disconnected (reason: ${reason}).`);
}
if (!reason || reason.length === 0) {
return new Error(`Request ${id} failed: websocket disconnected (code ${code}).`);
}