Bug 981875 - Improve error _PromiseWorker's error reporting in case of xpcom error. r=froydnj
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Sat, 15 Mar 2014 17:19:00 -0400
changeset 192022 2a5546bbe6311840cdbf9f1e75f4a3da7214372f
parent 192021 5d7cb798cd156ce2b5221ddbb953700fd199441d
child 192023 4944ac1b6a93ae2457b9cf2cef347a8a72288072
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs981875
milestone30.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 981875 - Improve error _PromiseWorker's error reporting in case of xpcom error. r=froydnj
toolkit/components/osfile/modules/_PromiseWorker.jsm
--- a/toolkit/components/osfile/modules/_PromiseWorker.jsm
+++ b/toolkit/components/osfile/modules/_PromiseWorker.jsm
@@ -171,18 +171,28 @@ PromiseWorker.prototype = {
    *
    * @return {promise}
    */
   post: function post(fun, array, closure) {
     let deferred = Promise.defer();
     let id = ++this._id;
     let message = {fun: fun, args: array, id: id};
     this._log("Posting message", message);
+    try {
+      this._worker.postMessage(message);
+    } catch (ex if typeof ex == "number") {
+      this._log("Could not post message", message, "due to xpcom error", ex);
+      // handle raw xpcom errors (see eg bug 961317)
+      return Promise.reject(new Components.Exception("Error in postMessage", ex));
+    } catch (ex) {
+      this._log("Could not post message", message, "due to error", ex);
+      return Promise.reject(ex);
+    }
+
     this._queue.push({deferred:deferred, closure: closure, id: id});
-    this._worker.postMessage(message);
     this._log("Message posted");
     return deferred.promise;
   }
 };
 
 /**
  * An error that has been serialized by the worker.
  *