Surface non-Error send failure details in renderer requests

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 09:12:03 +00:00
1 parent a4069fb203
commit cbd4ba0f74
2 files changed
+17 -4

No files matched your search

+15 -1
View File
@@ -7,6 +7,7 @@ class MockWebSocket {
static OPEN = 1;
static instances: MockWebSocket[] = [];
static failSend = false;
static failSendError: unknown = new Error("mock send failure");
static failOpen = false;
static failOpenEvent: unknown = {
message: "mock open failure",
@@ -52,7 +53,7 @@ class MockWebSocket {
send(data: string) {
if (MockWebSocket.failSend) {
throw new Error("mock send failure");
throw MockWebSocket.failSendError;
}
this.sentMessages.push(String(data));
@@ -128,6 +129,7 @@ describe("wsNativeApi", () => {
vi.resetModules();
MockWebSocket.instances = [];
MockWebSocket.failSend = false;
MockWebSocket.failSendError = new Error("mock send failure");
MockWebSocket.failOpen = false;
MockWebSocket.failOpenEvent = { message: "mock open failure" };
MockWebSocket.failConstruct = false;
@@ -211,6 +213,18 @@ describe("wsNativeApi", () => {
);
});
it("surfaces string send failure details when websocket send throws", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4502");
MockWebSocket.failSend = true;
MockWebSocket.failSendError = "string-send-failure";
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");
const api = getOrCreateWsNativeApi();
await expect(api.todos.list()).rejects.toThrow(
"Failed to send runtime request 'todos.list': string-send-failure",
);
});
it("recovers after a transient websocket send failure", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4480");
MockWebSocket.failSend = true;
+2 -3
View File
@@ -299,11 +299,10 @@ class WsNativeApiClient {
if (pending) {
clearTimeout(pending.timeout);
this.pending.delete(id);
const sendErrorMessage = messageFromUnknown(error);
pending.reject(
new Error(
`Failed to send runtime request '${method}': ${
error instanceof Error ? error.message : "unknown websocket failure"
}`,
`Failed to send runtime request '${method}': ${sendErrorMessage ?? "unknown websocket failure"}`,
),
);
}