Unexplainable "Unhandled rejection reasons (should be empty)"

124 views
Skip to first unread message

norm...@gmail.com

unread,
Jul 28, 2013, 5:00:43 PM7/28/13
to q-con...@googlegroups.com
I've noticed that I get the "Unhandled rejection reasons" message in my Chrome console, even though my promise has a .fail() to handle exceptions. Am I missing something?

d = Q.defer()

p = d.promise.fail(
    function(e) {
        console.log(e)
    }
).done()

d.reject("Some failure")

Also available as a jsFiddle: http://jsfiddle.net/SQwhM/2/

Am I missing something here?

Thanks

Norman Elton

Kris Kowal

unread,
Jul 28, 2013, 5:59:29 PM7/28/13
to Q Continuum
For the lack of better options, the message appears the first time a promise is rejected, and since there are no take-backsies on the console, there it stays. We try to only use the console message in environments that support live objects, meaning, the shown array will have the list of currently unhandled rejections, which in your case should just be [].

norm...@gmail.com

unread,
Jul 28, 2013, 6:43:22 PM7/28/13
to q-con...@googlegroups.com, kris....@cixar.com
Ahh, that message (especially "should be empty") makes much more sense now! Thanks.

Norman

norm...@gmail.com

unread,
Jul 28, 2013, 7:40:32 PM7/28/13
to q-con...@googlegroups.com
Sorry, one other phenomenon. It seems that this behavior is affected by the presence of a .finally block. If I throw a .finally after my .fail, the error remains "unhandled". Here's an example:

d = Q.defer()

d.promise.fail(
    function(e) {
        console.log("Got an error: " + e)
    }
)

d.promise.finally(
    function() {
       console.log("Finally, all done!")
    }
)

d.reject("Some failure")

setTimeout(function() {
    console.log(Q.getUnhandledReasons().length)
}, 1000)

It's online at http://jsfiddle.net/SQwhM/7/. When run, it seems that "Some failure" remains in the Q.getUnhandledReasons(). If I remove the .finally, it gets removed as expected.

Thoughts? Thanks again!

Norman
Reply all
Reply to author
Forward
0 new messages