Bug 992371 - avoid 'A promise chain failed to handle a rejection' errors using FxAccounts. r=jedp
authorMark Hammond <mhammond@skippinet.com.au>
Tue, 29 Apr 2014 08:46:14 +1000
changeset 181128 8bae1e18091d6dfca8064335c9abafdd1967822e
parent 181127 3b77d1ed52af2338fd0258b397d13cb2f7456747
child 181129 fd7ac192e4d83908e11e29fe109daebb9e7986fe
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersjedp
bugs992371
milestone31.0a1
Bug 992371 - avoid 'A promise chain failed to handle a rejection' errors using FxAccounts. r=jedp
services/fxaccounts/FxAccounts.jsm
services/fxaccounts/tests/xpcshell/test_accounts.js
--- a/services/fxaccounts/FxAccounts.jsm
+++ b/services/fxaccounts/FxAccounts.jsm
@@ -693,18 +693,24 @@ FxAccountsInternal.prototype = {
   startVerifiedCheck: function(data) {
     log.debug("startVerifiedCheck " + JSON.stringify(data));
     // Get us to the verified state, then get the keys. This returns a promise
     // that will fire when we are completely ready.
     //
     // Login is truly complete once keys have been fetched, so once getKeys()
     // obtains and stores kA and kB, it will fire the onverified observer
     // notification.
-    return this.whenVerified(data)
-      .then(() => this.getKeys());
+
+    // The callers of startVerifiedCheck never consume a returned promise (ie,
+    // this is simply kicking off a background fetch) so we must add a rejection
+    // handler to avoid runtime warnings about the rejection not being handled.
+    this.whenVerified(data).then(
+      () => this.getKeys(),
+      err => log.info("startVerifiedCheck promise was rejected: " + err)
+    );
   },
 
   whenVerified: function(data) {
     let currentState = this.currentAccountState;
     if (data.verified) {
       log.debug("already verified");
       return currentState.resolve(data);
     }
--- a/services/fxaccounts/tests/xpcshell/test_accounts.js
+++ b/services/fxaccounts/tests/xpcshell/test_accounts.js
@@ -316,19 +316,26 @@ add_test(function test_fetchAndUnwrapKey
   makeObserver(ONLOGOUT_NOTIFICATION, function() {
     log.debug("test_fetchAndUnwrapKeys_no_token observed logout");
     fxa.internal.getUserAccountData().then(user => {
       do_test_finished();
       run_next_test();
     });
   });
 
-  fxa.setSignedInUser(user).then((user) => {
-    fxa.internal.fetchAndUnwrapKeys();
-  });
+  fxa.setSignedInUser(user).then(
+    user => {
+      return fxa.internal.fetchAndUnwrapKeys();
+    }
+  ).then(
+    null,
+    error => {
+      log.info("setSignedInUser correctly rejected");
+    }
+  )
 });
 
 // Alice (User A) signs up but never verifies her email.  Then Bob (User B)
 // signs in with a verified email.  Ensure that no sign-in events are triggered
 // on Alice's behalf.  In the end, Bob should be the signed-in user.
 add_test(function test_overlapping_signins() {
   do_test_pending();