bug 1523104: remote: improve error legibility somewhat; r=ochameau
authorAndreas Tolfsen <ato@sny.no>
Wed, 27 Feb 2019 19:06:20 +0000
changeset 521112 11a98da764d1
parent 521111 40a677ed5cc4
child 521113 8a8c0dcb9486
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1523104
milestone67.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 1523104: remote: improve error legibility somewhat; r=ochameau
remote/Error.jsm
--- a/remote/Error.jsm
+++ b/remote/Error.jsm
@@ -13,56 +13,75 @@ var EXPORTED_SYMBOLS = [
 
 const {Log} = ChromeUtils.import("chrome://remote/content/Log.jsm");
 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyGetter(this, "log", Log.get);
 
 class RemoteAgentError extends Error {
-  constructor(...args) {
-    super(...args);
+  constructor(message = "", cause = undefined) {
+    super(cause);
+
     this.name = this.constructor.name;
+    this.message = message;
+    this.cause = cause;
+
     this.notify();
   }
 
   notify() {
     Cu.reportError(this);
-    log.error(formatError(this), this);
+    log.error(formatError(this));
+  }
+
+  format() {
+    return formatError(this);
   }
 }
 
 /**
  * A fatal error that it is not possible to recover from
  * or send back to the client.
  *
- * Constructing this error will cause the application to quit.
+ * Constructing this error will force the application to quit.
  */
 class FatalError extends RemoteAgentError {
   constructor(...args) {
     super(...args);
     this.quit();
   }
 
   notify() {
-    log.fatal(formatError(this, {stack: true}));
+    log.fatal(this.format());
+  }
+
+  format() {
+    return formatError(this, {stack: true});
   }
 
   quit(mode = Ci.nsIAppStartup.eForceQuit) {
     Services.startup.quit(mode);
   }
 }
 
+/** 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 s = [];
-  s.push(`${error.name}: ${error.message}`);
-  s.push("");
+  const ls = [];
+
+  ls.push(`${error.name}: ${error.message ? `${error.message}:` : ""}`);
+
   if (stack) {
-    s.push("Stacktrace:");
+    const stack = error.stack.trim().split("\n");
+    ls.push(stack.map(line => `\t${line}`).join("\n"));
+
+    if (error.cause) {
+      ls.push("caused by: " + formatError(error.cause, {stack}));
+    }
   }
-  s.push(error.stack);
 
-  return s.join("\n");
+  return ls.join("\n");
 }