mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-06-11 01:25:53 -04:00
Merge pull request #2527 from lightpanda-io/waitforselector-notfound
tools: map waitForSelector timeout to NodeNotFound
This commit is contained in:
@@ -961,9 +961,15 @@ fn execWaitForSelector(arena: std.mem.Allocator, session: *lp.Session, registry:
|
||||
|
||||
const timeout_ms = args.timeout orelse 5000;
|
||||
|
||||
const node = lp.actions.waitForSelector(args.selector, timeout_ms, session) catch |err| {
|
||||
if (err == error.InvalidSelector) return ToolError.InvalidParams;
|
||||
return ToolError.InternalError;
|
||||
const node = lp.actions.waitForSelector(args.selector, timeout_ms, session) catch |err| switch (err) {
|
||||
error.InvalidSelector => return ToolError.InvalidParams,
|
||||
// Timeout w/o a match: same outcome as `/hover selector=…` on a missing
|
||||
// node — surface `NodeNotFound` so the LLM sees a consistent signal.
|
||||
error.Timeout => return ToolError.NodeNotFound,
|
||||
else => {
|
||||
log.debug(.browser, "waitForSelector error", .{ .err = @errorName(err) });
|
||||
return ToolError.InternalError;
|
||||
},
|
||||
};
|
||||
|
||||
const registered = registry.register(node) catch return ToolError.InternalError;
|
||||
|
||||
@@ -886,14 +886,15 @@ test "MCP - waitForSelector: timeout" {
|
||||
);
|
||||
defer server.deinit();
|
||||
|
||||
// waitForSelector with a short timeout on a non-existent element should error
|
||||
// Missing element after the timeout surfaces as NodeNotFound, matching
|
||||
// the error /hover, /click, etc. produce when their selector misses.
|
||||
const msg =
|
||||
\\{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"waitForSelector","arguments":{"selector":"#nonexistent","timeout":100}}}
|
||||
;
|
||||
try router.handleMessage(server, testing.arena_allocator, msg);
|
||||
try testing.expectJson(.{
|
||||
.id = 1,
|
||||
.@"error" = struct {}{},
|
||||
.@"error" = .{ .message = "NodeNotFound" },
|
||||
}, out.written());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user