Bug 1525966 - Reject Error object instead of string in DevTools Front:onPacket r=nchevobbe

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Julian Descottes 2019-12-11 17:31:39 +00:00
parent 340788c614
commit 5bc4238d39
8 changed files with 15 additions and 13 deletions

View File

@ -93,7 +93,7 @@ async function _targetFromURL(client, id, type, chrome) {
try {
front = await client.mainRoot.getTab({ outerWindowID: id });
} catch (ex) {
if (ex.startsWith("Protocol error (noTab)")) {
if (ex.message.startsWith("Protocol error (noTab)")) {
throw new Error(
`targetFromURL, tab with outerWindowID '${id}' doesn't exist`
);

View File

@ -64,7 +64,10 @@ async function checkGetTabFailures(client) {
await client.mainRoot.getTab({ tabId: -999 });
ok(false, "getTab unexpectedly succeed with a wrong tabId");
} catch (error) {
is(error, "Protocol error (noTab): Unable to find tab with tabId '-999'");
is(
error.message,
"Protocol error (noTab): Unable to find tab with tabId '-999'"
);
}
try {
@ -72,7 +75,7 @@ async function checkGetTabFailures(client) {
ok(false, "getTab unexpectedly succeed with a wrong outerWindowID");
} catch (error) {
is(
error,
error.message,
"Protocol error (noTab): Unable to find tab with outerWindowID '-999'"
);
}

View File

@ -85,7 +85,7 @@ function testAttachRemovedTab() {
gTab2Front.attach().then(null, error => {
ok(
error.includes("noSuchActor"),
error.message.includes("noSuchActor"),
"Actor is gone since the tab was removed."
);
deferred.resolve();

View File

@ -83,7 +83,7 @@ function runTests() {
() => ok(false, "getCharPref should've thrown for an undefined preference"),
(ex) => {
is(
ex,
ex.message,
"Protocol error (unknownError): preference is not of the right type: test.undefined",
"getCharPref should throw an exception with the preference name"
);

View File

@ -48,7 +48,7 @@ async function test_object_grip(debuggee, threadFront) {
await method.apply(obj, []);
Assert.ok(false, "expected exception");
} catch (err) {
Assert.ok(!!err.match(/debugee object is not callable/));
Assert.ok(!!err.message.match(/debugee object is not callable/));
}
}

View File

@ -42,7 +42,7 @@ function test_pause_frame() {
ok(false, "bogusRequest should throw");
} catch (e) {
ok(true, "bogusRequest thrown");
Assert.ok(!!e.match(/unrecognizedPacketType/));
Assert.ok(!!e.message.match(/unrecognizedPacketType/));
}
Assert.ok(objectFront.valid);
@ -55,7 +55,7 @@ function test_pause_frame() {
ok(false, "bogusRequest should throw");
} catch (e) {
ok(true, "bogusRequest thrown");
Assert.ok(!!e.match(/noSuchActor/));
Assert.ok(!!e.message.match(/noSuchActor/));
}
Assert.ok(!objectFront.valid);
threadFrontTestFinished();

View File

@ -56,8 +56,8 @@ function test_thread_lifetime() {
try {
await objFront2
.request({ to: pauseGrip.actor, type: "bogusRequest" })
.catch(function(response) {
Assert.ok(!!response.match(/noSuchActor/));
.catch(function(error) {
Assert.ok(!!error.message.match(/noSuchActor/));
gThreadFront.resume().then(function() {
threadFrontTestFinished();
});

View File

@ -266,8 +266,6 @@ class Front extends Pool {
callFunctionWithAsyncStack(
() => {
if (packet.error) {
// "Protocol error" is here to avoid TBPL heuristics. See also
// https://dxr.mozilla.org/webtools-central/source/tbpl/php/inc/GeneralErrorFilter.php
let message;
if (packet.error && packet.message) {
message =
@ -275,7 +273,8 @@ class Front extends Pool {
} else {
message = packet.error;
}
deferred.reject(message);
const packetError = new Error(message);
deferred.reject(packetError);
} else {
deferred.resolve(packet);
}