Bug 1533679 - Print exceptions thrown by JSON handlers. r=ato
authorAlexandre Poirot <poirot.alex@gmail.com>
Sun, 10 Mar 2019 12:52:48 +0000
changeset 521282 600543aa900a140ddff9169e1561fcfa75029d55
parent 521281 f46ddc90587ccdfaa730a3b85128ad25159b5bca
child 521283 13431774ebecef49330788fdd19fa2fd61c5eb06
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)
reviewersato
bugs1533679
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 1533679 - Print exceptions thrown by JSON handlers. r=ato Without that, the exception is silented. Depends on D22688 Differential Revision: https://phabricator.services.mozilla.com/D22689
remote/JSONHandler.jsm
--- a/remote/JSONHandler.jsm
+++ b/remote/JSONHandler.jsm
@@ -1,19 +1,20 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 var EXPORTED_SYMBOLS = ["JSONHandler"];
 
-const {HTTP_404} = ChromeUtils.import("chrome://remote/content/server/HTTPD.jsm");
+const {HTTP_404, HTTP_505} = ChromeUtils.import("chrome://remote/content/server/HTTPD.jsm");
 const {Log} = ChromeUtils.import("chrome://remote/content/Log.jsm");
 const {Protocol} = ChromeUtils.import("chrome://remote/content/Protocol.jsm");
+const {RemoteAgentError} = ChromeUtils.import("chrome://remote/content/Error.jsm");
 
 class JSONHandler {
   constructor(agent) {
     this.agent = agent;
     this.routes = {
       "/json/version": this.getVersion.bind(this),
       "/json/protocol": this.getProtocol.bind(this),
       "/json/list": this.getTargetList.bind(this),
@@ -38,22 +39,27 @@ class JSONHandler {
     if (request.method != "GET") {
       throw HTTP_404;
     }
 
     if (!(request.path in this.routes)) {
       throw HTTP_404;
     }
 
-    const body = this.routes[request.path]();
-    const payload = JSON.stringify(body, sanitise, Log.verbose ? "\t" : undefined);
+    try {
+      const body = this.routes[request.path]();
+      const payload = JSON.stringify(body, sanitise, Log.verbose ? "\t" : undefined);
 
-    response.setStatusLine(request.httpVersion, 200, "OK");
-    response.setHeader("Content-Type", "application/json");
-    response.write(payload);
+      response.setStatusLine(request.httpVersion, 200, "OK");
+      response.setHeader("Content-Type", "application/json");
+      response.write(payload);
+    } catch (e) {
+      new RemoteAgentError(e).notify();
+      throw HTTP_505;
+    }
   }
 
   // XPCOM
 
   get QueryInterface() {
     return ChromeUtils.generateQI([Ci.nsIHttpRequestHandler]);
   }
 }