forked from mirrors/gecko-dev
bug 1540684: remote: fix stray colons in error formatting; r=ochameau
Error messages contained extraneous colons that were inconsistent with how JavaScript errors are usually formatted. Examples of ill-formed formatting: FooError: FooError: bar: The trailing colons should not be present in either of these cases. Colons should only be printed when something follows. For example: FooError FooError: bar FooError: bar: test.js:42 Differential Revision: https://phabricator.services.mozilla.com/D25608 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
924a19a629
commit
9936854ecf
3 changed files with 17 additions and 9 deletions
|
|
@ -3,5 +3,6 @@
|
|||
module.exports = {
|
||||
"rules": {
|
||||
"max-len": "off",
|
||||
"no-tabs": "off",
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -71,18 +71,25 @@ class UnsupportedError extends RemoteAgentError {}
|
|||
class UnknownMethodError extends RemoteAgentError {}
|
||||
|
||||
function formatError(error, {stack = false} = {}) {
|
||||
const ls = [];
|
||||
const els = [];
|
||||
|
||||
ls.push(`${error.name}: ${error.message ? `${error.message}:` : ""}`);
|
||||
els.push(error.name);
|
||||
if (error.message) {
|
||||
els.push(": ");
|
||||
els.push(error.message);
|
||||
}
|
||||
|
||||
if (stack && error.stack) {
|
||||
els.push(":\n");
|
||||
|
||||
const stack = error.stack.trim().split("\n");
|
||||
ls.push(stack.map(line => `\t${line}`).join("\n"));
|
||||
els.push(stack.map(line => `\t${line}`).join("\n"));
|
||||
|
||||
if (error.cause) {
|
||||
ls.push("caused by: " + formatError(error.cause, {stack}));
|
||||
els.push("\n");
|
||||
els.push("caused by: " + formatError(error.cause, {stack}));
|
||||
}
|
||||
}
|
||||
|
||||
return ls.join("\n");
|
||||
return els.join("");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,15 +46,15 @@ add_test(function test_RemoteAgentError_toString() {
|
|||
add_test(function test_RemoteAgentError_format() {
|
||||
const {format} = RemoteAgentError;
|
||||
|
||||
equal(format({name: "HippoError"}), "HippoError: ");
|
||||
equal(format({name: "HorseError", message: "neigh"}), "HorseError: neigh:");
|
||||
equal(format({name: "HippoError"}), "HippoError");
|
||||
equal(format({name: "HorseError", message: "neigh"}), "HorseError: neigh");
|
||||
|
||||
const dog = {
|
||||
name: "DogError",
|
||||
message: "woof",
|
||||
stack: " one\ntwo\nthree ",
|
||||
};
|
||||
equal(format(dog), "DogError: woof:");
|
||||
equal(format(dog), "DogError: woof");
|
||||
equal(format(dog, {stack: true}),
|
||||
`DogError: woof:
|
||||
one
|
||||
|
|
@ -67,7 +67,7 @@ add_test(function test_RemoteAgentError_format() {
|
|||
stack: "four\nfive\nsix",
|
||||
cause: dog,
|
||||
};
|
||||
equal(format(cat), "CatError: meow:");
|
||||
equal(format(cat), "CatError: meow");
|
||||
equal(format(cat, {stack: true}),
|
||||
`CatError: meow:
|
||||
four
|
||||
|
|
|
|||
Loading…
Reference in a new issue