bug 1540684: remote: fix stray colons in error formatting; r=ochameau
authorAndreas Tolfsen <ato@sny.no>
Thu, 04 Apr 2019 09:55:14 +0000
changeset 467953 304f28818b0f9a9c1dbc11a9c517248e03c6b8d4
parent 467952 6fba6453b064f32ea55c774e3e6357ca4354832d
child 467954 f8e989e26332761a57a346eaf705d34731c962f6
push id112667
push useraiakab@mozilla.com
push dateThu, 04 Apr 2019 16:12:45 +0000
treeherdermozilla-inbound@230bb363f2f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1540684
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
remote/.eslintrc.js
remote/Error.jsm
remote/test/unit/test_Error.js
--- a/remote/.eslintrc.js
+++ b/remote/.eslintrc.js
@@ -1,7 +1,8 @@
 "use strict";
 
 module.exports = {
   "rules": {
     "max-len": "off",
+    "no-tabs": "off",
   }
 };
--- a/remote/Error.jsm
+++ b/remote/Error.jsm
@@ -66,23 +66,30 @@ class FatalError extends RemoteAgentErro
 
 /** When an operation is not yet implemented. */
 class UnsupportedError extends RemoteAgentError {}
 
 /** The requested remote method does not exist. */
 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("");
 }
--- a/remote/test/unit/test_Error.js
+++ b/remote/test/unit/test_Error.js
@@ -41,38 +41,38 @@ add_test(function test_RemoteAgentError_
   equal(e.toString({stack: true}), RemoteAgentError.format(e, {stack: true}));
 
   run_next_test();
 });
 
 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
 	two
 	three`);
 
   const cat = {
     name: "CatError",
     message: "meow",
     stack: "four\nfive\nsix",
     cause: dog,
   };
-  equal(format(cat), "CatError: meow:");
+  equal(format(cat), "CatError: meow");
   equal(format(cat, {stack: true}),
 `CatError: meow:
 	four
 	five
 	six
 caused by: DogError: woof:
 	one
 	two