Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant