From a2e66f85a1e7bad26658752be99eaa5e462d5d6d Mon Sep 17 00:00:00 2001 From: Navid EMAD Date: Sun, 15 Mar 2026 04:36:47 +0100 Subject: [PATCH] fix(cdp): don't kill WebSocket on unknown domain/method errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a CDP command with an unrecognized domain (e.g. `NonExistent.method`) was sent, the error response was correctly returned but the connection died immediately after. This happened because dispatch() re-returned the error after sending the error response, which propagated up through processMessage() → handleMessage() where `catch return false` closed the WebSocket connection. Now the error is only propagated if sendError itself fails (e.g. broken pipe). Otherwise dispatch() returns normally and the read loop continues. Fixes #1843 Co-Authored-By: Claude Opus 4.6 --- src/cdp/cdp.zig | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cdp/cdp.zig b/src/cdp/cdp.zig index 08055d86..58ed11b9 100644 --- a/src/cdp/cdp.zig +++ b/src/cdp/cdp.zig @@ -168,13 +168,11 @@ pub fn CDPT(comptime TypeProvider: type) type { if (is_startup) { dispatchStartupCommand(&command, input.method) catch |err| { - command.sendError(-31999, @errorName(err), .{}) catch {}; - return err; + command.sendError(-31999, @errorName(err), .{}) catch return err; }; } else { dispatchCommand(&command, input.method) catch |err| { - command.sendError(-31998, @errorName(err), .{}) catch {}; - return err; + command.sendError(-31998, @errorName(err), .{}) catch return err; }; } } @@ -924,18 +922,20 @@ test "cdp: invalid json" { // method is required try testing.expectError(error.InvalidJSON, ctx.processMessage(.{})); - try testing.expectError(error.InvalidMethod, ctx.processMessage(.{ + try ctx.processMessage(.{ .method = "Target", - })); + }); try ctx.expectSentError(-31998, "InvalidMethod", .{}); - try testing.expectError(error.UnknownDomain, ctx.processMessage(.{ + try ctx.processMessage(.{ .method = "Unknown.domain", - })); + }); + try ctx.expectSentError(-31998, "UnknownDomain", .{}); - try testing.expectError(error.UnknownMethod, ctx.processMessage(.{ + try ctx.processMessage(.{ .method = "Target.over9000", - })); + }); + try ctx.expectSentError(-31998, "UnknownMethod", .{}); } test "cdp: invalid sessionId" {