Automatic update from web-platform-tests WebMCP: Stop reporting exceptions on tool failure In http://b/477213243 we identified that it was useful to print to the console, the exact failure that a failed WebMCP tool call encountered, to ease debugging. To fix this, https://crrev.com/c/7497712 introduced a call to `V8ScriptRunner::ReportException()`, which reports to the console, but also has the script-observable side-effect of firing the `error` event at Window, per the HTML Standard [1]. Doing so from a rejected Promise reaction is very unusual, so this CL fixes this by adding a message to the console instead, avoiding the script-observable behavior of firing the `error` event. This CL also adds a WPT to protect against this. This test fails without the implementation change in this CL. [1]: https://html.spec.whatwg.org/C#report-the-error R=beaufort.francois@gmail.com, khushalsagar Bug: 477213243 Change-Id: I5240b12ec973cea868b92c96ef835c6d5b9c2102 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8063044 Commit-Queue: Dominic Farolino <dom@chromium.org> Reviewed-by: Fr <beaufort.francois@gmail.com> Cr-Commit-Position: refs/heads/main@{#1658648} -- wpt-commits: d1140fb599306f0dd3ce3e6f97514d26202fac2d wpt-pr: 61144
44 lines
1.3 KiB
HTML
44 lines
1.3 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>WebMCP failed tool execution does not fire window.onerror</title>
|
|
<link rel="author" href="mailto:dom@chromium.org">
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
promise_test(async t => {
|
|
let errorFired = false;
|
|
const errorHandler = () => {
|
|
errorFired = true;
|
|
};
|
|
window.addEventListener('error', errorHandler);
|
|
t.add_cleanup(() => {
|
|
window.removeEventListener('error', errorHandler);
|
|
});
|
|
|
|
// Register a tool that throws an error when executed.
|
|
await document.modelContext.registerTool({
|
|
name: 'throwing_tool',
|
|
description: 'A tool that throws an error',
|
|
execute: async () => {
|
|
throw new Error('Tool execution failed intentionally');
|
|
}
|
|
});
|
|
|
|
const tools = await document.modelContext.getTools();
|
|
const tool = tools.find(t => t.name === 'throwing_tool');
|
|
assert_true(!!tool, 'Should find the registered tool');
|
|
|
|
// `executeTool()` should reject since the tool execution failed.
|
|
await promise_rejects_dom(t, 'UnknownError',
|
|
document.modelContext.executeTool(tool, '{}'),
|
|
'executeTool() rejects when the tool execution throws');
|
|
|
|
assert_false(errorFired, 'window.onerror/error event should not be fired');
|
|
}, 'Failed tool execution does not trigger window.onerror');
|
|
</script>
|
|
</body>
|
|
</html>
|