From 05de47149f917aec448f43175e2443bc875ad8a9 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 27 Apr 2016 02:32:58 -0400 Subject: [PATCH] Allow marking of errors as handled for Bluebird Set .handledRejection on an Error object to tell Bluebird that it's been handled and shouldn't be logged by onPossiblyUnhandledRejection(). --- resource/bluebird.js | 5 +---- resource/concurrentCaller.js | 1 + test/tests/concurrentCallerTest.js | 12 ++++++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/resource/bluebird.js b/resource/bluebird.js index e59988d1e..881f0820d 100644 --- a/resource/bluebird.js +++ b/resource/bluebird.js @@ -96,13 +96,10 @@ }); // TEMP: Only turn on if debug logging enabled? Promise.onPossiblyUnhandledRejection(function (e, promise) { - if (e.name == 'ZoteroPromiseInterrupt') { + if (e.name == 'ZoteroPromiseInterrupt' || e.handledRejection) { return; } - // Ignore some errors during tests - if (e.message && e.message.indexOf(' -- ignore') != -1) return; - self.debug('Possibly unhandled rejection:\n\n' + e.message); throw e; }); diff --git a/resource/concurrentCaller.js b/resource/concurrentCaller.js index e4155eb60..34861b44a 100644 --- a/resource/concurrentCaller.js +++ b/resource/concurrentCaller.js @@ -246,6 +246,7 @@ ConcurrentCaller.prototype._processNext = function () { this._processNext(); }); + e.handledRejection = true; f.deferred.reject(e); }); return true; diff --git a/test/tests/concurrentCallerTest.js b/test/tests/concurrentCallerTest.js index 1cea84602..caa3b2d9d 100644 --- a/test/tests/concurrentCallerTest.js +++ b/test/tests/concurrentCallerTest.js @@ -206,8 +206,10 @@ describe("ConcurrentCaller", function () { Zotero.debug("Throwing " + id); // This causes an erroneous "possibly unhandled rejection" message in // Bluebird 2.10.2 that I can't seem to get rid of (and the rejection - // is later handled), so pass " -- ignore" to tell Bluebird to ignore it - throw new Error("Fail -- ignore"); + // is later handled), so tell Bluebird to ignore it + let e = new Error("Fail"); + e.handledRejection = true; + throw e; } if (running > numConcurrent) { failed = true; @@ -279,8 +281,10 @@ describe("ConcurrentCaller", function () { Zotero.debug("Throwing " + id); // This causes an erroneous "possibly unhandled rejection" message in // Bluebird 2.10.2 that I can't seem to get rid of (and the rejection - // is later handled), so pass " -- ignore" to tell Bluebird to ignore it - throw new Error("Fail -- ignore"); + // is later handled), so tell Bluebird to ignore it + let e = new Error("Fail"); + e.handledRejection = true; + throw e; } if (running > numConcurrent) { failed = true;