Cover renderer constructor error message normalization edge cases

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 08:36:05 +00:00
1 parent 73794df6fa
commit 90f6d84729
1 file changed
+25 -1
+25 -1
View File
@@ -12,6 +12,7 @@ class MockWebSocket {
message: "mock open failure",
};
static failConstruct = false;
static failConstructError: unknown = new Error("mock constructor failure");
static failCloseBeforeOpen = false;
static failCloseBeforeOpenEvent: { code?: number; reason?: string } = {
code: WS_CLOSE_CODES.unauthorized,
@@ -25,7 +26,7 @@ class MockWebSocket {
constructor(readonly url: string) {
if (MockWebSocket.failConstruct) {
throw new Error("mock constructor failure");
throw MockWebSocket.failConstructError;
}
MockWebSocket.instances.push(this);
queueMicrotask(() => {
@@ -130,6 +131,7 @@ describe("wsNativeApi", () => {
MockWebSocket.failOpen = false;
MockWebSocket.failOpenEvent = { message: "mock open failure" };
MockWebSocket.failConstruct = false;
MockWebSocket.failConstructError = new Error("mock constructor failure");
MockWebSocket.failCloseBeforeOpen = false;
MockWebSocket.failCloseBeforeOpenEvent = {
code: WS_CLOSE_CODES.unauthorized,
@@ -1979,6 +1981,28 @@ describe("wsNativeApi", () => {
);
});
it("uses non-Error constructor message when websocket construction throws", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4493");
MockWebSocket.failConstruct = true;
MockWebSocket.failConstructError = { message: "object-constructor-failure" };
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");
const api = getOrCreateWsNativeApi();
await expect(api.todos.list()).rejects.toThrow(
"Failed to connect to local t3 runtime: websocket error (object-constructor-failure).",
);
});
it("falls back to generic connect error when constructor message is whitespace", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4494");
MockWebSocket.failConstruct = true;
MockWebSocket.failConstructError = { message: " " };
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");
const api = getOrCreateWsNativeApi();
await expect(api.todos.list()).rejects.toThrow("Failed to connect to local t3 runtime.");
});
it("recovers after websocket construction failure on next request", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4427");
MockWebSocket.failConstruct = true;