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

unhandledRejection does not provide promise.stack #835

Closed
arikwex opened this issue Aug 14, 2018 · 1 comment
Closed

unhandledRejection does not provide promise.stack #835

arikwex opened this issue Aug 14, 2018 · 1 comment

Comments

@arikwex
Copy link

arikwex commented Aug 14, 2018

(Praying I did a good dupe check before submitting this)

I'm running a node process that catches any unhandledRejections. I'd like to hunt down all offenders in my app by viewing promise.stack when an unhandledRejection is emitted. Sample app:

const Q = require('q');
Q.longStackSupport = true;

// Unhandled rejection for node
process.on('unhandledRejection', (reason, promise) => {
  console.log(`Unhandled rejection reason: ${reason}`);
  console.log(`Unhandled rejection has stack: ${promise.stack ? 'true' : 'false'}`);
});

// Create an unhandled rejection
const d = Q.defer();
d.reject('denied!');
console.log(`Promise reason: ${d.promise.source.exception}`);
console.log(`Promise has stack: ${d.promise.stack ? 'true' : 'false'}`);

Output:

Promise reason: denied!
Promise has stack: true
Unhandled rejection reason: denied!
Unhandled rejection has stack: false

My issue is that the unhandledRejection event provides a promise that does not contain the stack information. Am I doing something wrong here? or is this working as intended?

@arikwex arikwex changed the title unhandledRejection does not contain promise.stack unhandledRejection does not provide promise.stack Aug 14, 2018
@kriskowal
Copy link
Owner

Try Q.reject(new Error("denied!")). Reject is analogous to throw and you only get a stack trace if you use an Error object instance.

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

No branches or pull requests

2 participants