mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-21 20:24:42 +00:00
fix(cdp): don't kill WebSocket on unknown domain/method errors
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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" {
|
||||
|
||||
Reference in New Issue
Block a user