Bug 1273343 - make more log noise on resource exceptions and errors. r=tcsc draft
authorMark Hammond <mhammond@skippinet.com.au>
Thu, 25 Aug 2016 18:33:01 +1000
changeset 405962 3862227737e934e21551ef9ca8ae10c25cb67a9a
parent 405272 a5571e6af4e9655ba6af3cb972286697f24813d1
child 407232 42a6f3ac8c6e05cd15a61ee7cdb0d29417a02961
push id27615
push userbmo:markh@mozilla.com
push dateFri, 26 Aug 2016 07:21:15 +0000
reviewerstcsc
bugs1273343
milestone51.0a1
Bug 1273343 - make more log noise on resource exceptions and errors. r=tcsc MozReview-Commit-ID: 6pa8MvoNnwb
services/sync/modules/resource.js
services/sync/tests/unit/test_resource.js
--- a/services/sync/modules/resource.js
+++ b/services/sync/modules/resource.js
@@ -301,16 +301,19 @@ AsyncResource.prototype = {
     }
 
     let ret     = new String(data);
     ret.url     = channel.URI.spec;
     ret.status  = status;
     ret.success = success;
     ret.headers = headers;
 
+    if (!success) {
+      this._log.warn(`${action} request to ${ret.url} failed with status ${status}`);
+    }
     // Make a lazy getter to convert the json response into an object.
     // Note that this can cause a parse error to be thrown far away from the
     // actual fetch, so be warned!
     XPCOMUtils.defineLazyGetter(ret, "obj", function() {
       try {
         return JSON.parse(ret);
       } catch (ex) {
         this._log.warn("Got exception parsing response body", ex);
@@ -380,16 +383,18 @@ Resource.prototype = {
     // The channel listener might get a failure code
     try {
       this._doRequest(action, data, callback);
       return Async.waitForSyncCallback(cb);
     } catch (ex) {
       if (Async.isShutdownException(ex)) {
         throw ex;
       }
+      this._log.warn("${action} request to ${url} failed: ${ex}",
+                     { action, url: this.uri.spec, ex });
       // Combine the channel stack with this request stack.  Need to create
       // a new error object for that.
       let error = Error(ex.message);
       error.result = ex.result;
       let chanStack = [];
       if (ex.stack)
         chanStack = ex.stack.trim().split(/\n/).slice(1);
       let requestStack = error.stack.split(/\n/).slice(1);
--- a/services/sync/tests/unit/test_resource.js
+++ b/services/sync/tests/unit/test_resource.js
@@ -437,16 +437,18 @@ function run_test() {
     content = res18.get();
   } catch (ex) {
     error = ex;
   }
 
   // It throws and logs.
   do_check_eq(error.result, Cr.NS_ERROR_MALFORMED_URI);
   do_check_eq(error, "Error: NS_ERROR_MALFORMED_URI");
+  // Note the strings haven't been formatted yet, but that's OK for this test.
+  do_check_eq(warnings.pop(), "${action} request to ${url} failed: ${ex}");
   do_check_eq(warnings.pop(),
               "Got exception calling onProgress handler during fetch of " +
               server.baseURI + "/json");
 
   // And this is what happens if JS throws an exception.
   res18 = new Resource(server.baseURI + "/json");
   onProgress = function(rec) {
     throw "BOO!";
@@ -460,16 +462,17 @@ function run_test() {
     content = res18.get();
   } catch (ex) {
     error = ex;
   }
 
   // It throws and logs.
   do_check_eq(error.result, Cr.NS_ERROR_XPC_JS_THREW_STRING);
   do_check_eq(error, "Error: NS_ERROR_XPC_JS_THREW_STRING");
+  do_check_eq(warnings.pop(), "${action} request to ${url} failed: ${ex}");
   do_check_eq(warnings.pop(),
               "Got exception calling onProgress handler during fetch of " +
               server.baseURI + "/json");
 
 
   _("Ensure channel timeouts are thrown appropriately.");
   let res19 = new Resource(server.baseURI + "/json");
   res19.ABORT_TIMEOUT = 0;