Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Adds a Q.getUnhandledRejectionValues() function #816

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

timmfin
Copy link

@timmfin timmfin commented Jun 16, 2017

The purpose of Q.getUnhandledRejectionValues() is for debug access to actual rejection values, because Q.getUnhandledReasons() only provides a string representation of rejections. And that string representation can often be pretty useless, particularly when code is intentionally or accidentally rejecting non-error values (I've seen legacy CoffeeScript do that a bunch due to automatic returns). Also when live debugging a problem, having an actual rejection reference lets you inspect deeper, like if you set custom properties on an error, etc.

Some examples:

Q.reject('foobar');
// => Promise {exception: "foobar"}

Q.getUnhandledReasons()
// => ["(no stack) foobar"]

Q.getUnhandledRejectionValues()
// => ["foobar"]
Q.reject({ foo: "bar" })

Q.getUnhandledReasons();
// => ["(no stack) [object Object]"]

Q.getUnhandledRejectionValues()
// => { foo: "bar" }
CustomClass = function () {}
Q.reject(new CustomClass)

Q.getUnhandledReasons();
// => ["(no stack) [object Object]"]

Q.getUnhandledRejectionValues()
// => CustomClass instance

I've added a couple basic tests for Q.getUnhandledRejectionValues(), ensured npm test was green, and ran q-spec.html in a few browsers (latest Chrome, Firefox, and Safari).

timmfin added 3 commits June 16, 2017 13:15
…he actual rejection values (and not only the string-ified reasons in `Q.getUnhandledReasons()`).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant