Bug 1495473 - Properly propagate the error up to the client r=ochameau
authorJulien Wajsberg <felash@gmail.com>
Mon, 15 Oct 2018 17:33:58 +0000
changeset 497049 7e55a78b333997c6ccf98ee3669dc284648ea3c8
parent 497048 835e3524a6caa63d1b6d1dc84077e900cc56873b
child 497050 ba86672c033d9578ec99d0aa70eecbfedac28b46
push id9996
push userarchaeopteryx@coole-files.de
push dateThu, 18 Oct 2018 18:37:15 +0000
treeherdermozilla-beta@8efe26839243 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1495473
milestone64.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 1495473 - Properly propagate the error up to the client r=ochameau Differential Revision: https://phabricator.services.mozilla.com/D7299
devtools/shared/fronts/memory.js
--- a/devtools/shared/fronts/memory.js
+++ b/devtools/shared/fronts/memory.js
@@ -57,35 +57,50 @@ const MemoryFront = protocol.FrontClassW
    * Given that we have taken a heap snapshot with the given id, transfer the
    * heap snapshot file to the client. The path to the client's local file is
    * returned.
    *
    * @param {String} snapshotId
    *
    * @returns Promise<String>
    */
-  transferHeapSnapshot: protocol.custom(function(snapshotId) {
+  transferHeapSnapshot: protocol.custom(async function(snapshotId) {
     if (!this.heapSnapshotFileActorID) {
       throw new Error("MemoryFront initialized without a rootForm");
     }
 
-    const request = this._client.request({
-      to: this.heapSnapshotFileActorID,
-      type: "transferHeapSnapshot",
-      snapshotId
-    });
+    try {
+      const request = this._client.request({
+        to: this.heapSnapshotFileActorID,
+        type: "transferHeapSnapshot",
+        snapshotId
+      });
 
-    return new Promise((resolve, reject) => {
       const outFilePath =
         HeapSnapshotFileUtils.getNewUniqueHeapSnapshotTempFilePath();
       const outFile = new FileUtils.File(outFilePath);
+      const outFileStream = FileUtils.openSafeFileOutputStream(outFile);
 
-      const outFileStream = FileUtils.openSafeFileOutputStream(outFile);
-      request.on("bulk-reply", async function({ copyTo }) {
-        await copyTo(outFileStream);
-        FileUtils.closeSafeFileOutputStream(outFileStream);
-        resolve(outFilePath);
-      });
-    });
+      // This request is a bulk request. That's why the result of the request is
+      // an object with the `copyTo` function that can transfer the data to
+      // another stream.
+      // See devtools/shared/transport/transport.js to know more about this mode.
+      const { copyTo } = await request;
+      await copyTo(outFileStream);
+
+      FileUtils.closeSafeFileOutputStream(outFileStream);
+      return outFilePath;
+    } catch (e) {
+      if (e.error) {
+        // This isn't a real error, rather this is a message coming from the
+        // server. So let's throw a real error instead.
+        throw new Error(
+          `The server's actor threw an error: (${e.error}) ${e.message}`
+        );
+      }
+
+      // Otherwise, rethrow the error
+      throw e;
+    }
   })
 });
 
 exports.MemoryFront = MemoryFront;