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

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 : source : f3d44dbce7e3d1b529ce37b21a4d7471a918edd4
extra : histedit_source : df4d534565efb3e2babbc277a3aecce5d534ac39
This commit is contained in:
Andreas Tolfsen 2019-05-27 11:39:16 +00:00
parent c7510faa29
commit de8c9e85cf
6 changed files with 49 additions and 9 deletions

View File

@ -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 = [];

View File

@ -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,

View File

@ -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);

View File

@ -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]

View File

@ -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();
});

View File

@ -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();
});