bug 1553317: remote: improve error message on missing method; r=remote-protocol-reviewers,ochameau

We return with this rather omnious message when we are missing the
implementation of a CDP method:

	Error: Protocol error (Target.createBrowserContext): TypeError: inst[command] is not a function:

This patch improves the error message so that debugging is not
necessary to find out which domain or command is missing.

Ideally Session.jsm and ContentProcessSession.jsm would share the
same execute() function (there's really not reason they don't),
but that involves more work.

Differential Revision: https://phabricator.services.mozilla.com/D32069

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andreas Tolfsen 2019-05-27 11:39:16 +00:00
Родитель 998419a429
Коммит 26201b29a2
6 изменённых файлов: 49 добавлений и 9 удалений

Просмотреть файл

@ -100,7 +100,15 @@ class FatalError extends RemoteAgentError {
class UnsupportedError extends RemoteAgentError {}
/** The requested remote method does not exist. */
class UnknownMethodError extends RemoteAgentError {}
class UnknownMethodError extends RemoteAgentError {
constructor(domain, command = null) {
if (command) {
super(`${domain}.${command}`);
} else {
super(domain);
}
}
}
function formatError(error, {stack = false} = {}) {
const els = [];

Просмотреть файл

@ -8,6 +8,7 @@ var EXPORTED_SYMBOLS = ["ContentProcessSession"];
const {ContentProcessDomains} = ChromeUtils.import("chrome://remote/content/domains/ContentProcessDomains.jsm");
const {Domains} = ChromeUtils.import("chrome://remote/content/domains/Domains.jsm");
const {UnknownMethodError} = ChromeUtils.import("chrome://remote/content/Error.jsm");
class ContentProcessSession {
constructor(messageManager, browsingContext, content, docShell) {
@ -61,14 +62,11 @@ class ContentProcessSession {
case "remote:request":
try {
const {id, domain, command, params} = data.request;
const inst = this.domains.get(domain);
const func = inst[command];
if (!func || typeof func != "function") {
throw new Error(`Implementation missing: ${domain}.${command}`);
if (!this.domains.domainSupportsMethod(domain, command)) {
throw new UnknownMethodError(domain, command);
}
const result = await func.call(inst, params);
const inst = this.domains.get(domain);
const result = await inst[command](params);
this.messageManager.sendAsyncMessage("remote:result", {
browsingContextId,

Просмотреть файл

@ -8,7 +8,10 @@ var EXPORTED_SYMBOLS = ["Session"];
const {ParentProcessDomains} = ChromeUtils.import("chrome://remote/content/domains/ParentProcessDomains.jsm");
const {Domains} = ChromeUtils.import("chrome://remote/content/domains/Domains.jsm");
const {RemoteAgentError} = ChromeUtils.import("chrome://remote/content/Error.jsm");
const {
RemoteAgentError,
UnknownMethodError,
} = ChromeUtils.import("chrome://remote/content/Error.jsm");
/**
* A session represents exactly one client WebSocket connection.
@ -69,6 +72,9 @@ class Session {
}
async execute(id, domain, command, params) {
if (!this.domains.domainSupportsMethod(domain, command)) {
throw new UnknownMethodError(domain, command);
}
const inst = this.domains.get(domain);
const result = await inst[command](params);
this.onResult(id, result);

Просмотреть файл

@ -16,5 +16,6 @@ support-files =
[browser_runtime_callFunctionOn.js]
[browser_runtime_executionContext.js]
skip-if = os == "mac" || (verify && os == 'win') # bug 1547961
[browser_session.js]
[browser_tabs.js]
[browser_target.js]

Просмотреть файл

@ -0,0 +1,25 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function() {
await RemoteAgent.listen(Services.io.newURI("http://localhost:9222"));
const CDP = await getCDP();
const {webSocketDebuggerUrl} = await CDP.Version();
const client = await CDP({"target": webSocketDebuggerUrl});
try {
await client.send("Hoobaflooba");
} catch (e) {
ok(e.message.match(/TypeError: Invalid method format/));
}
try {
await client.send("Hooba.flooba");
} catch (e) {
ok(e.message.match(/UnknownMethodError/));
}
await client.close();
await RemoteAgent.close();
});

Просмотреть файл

@ -100,5 +100,7 @@ add_test(function test_UnsupportedError() {
add_test(function test_UnknownMethodError() {
ok(new UnknownMethodError() instanceof RemoteAgentError);
ok(new UnknownMethodError("domain").message.endsWith("domain"));
ok(new UnknownMethodError("domain", "command").message.endsWith("domain.command"));
run_next_test();
});