Skip to content
This repository was archived by the owner on Aug 31, 2024. It is now read-only.

Conversation

parshap
Copy link
Contributor

@parshap parshap commented Jan 13, 2016

I had an issue where a synchronous error thrown in the callback I passed to toArray was swallowed and never reported to me like I would expect. This happens because the callback executes in a promise.then() callback stack trace. The promise implementation catches the error and doesn't report it other than via the "unhandledRejection" event. I am not using promises in my application code so I don't have an "unhandledRejection" handler (and wasn't even aware of it). It took me a while to track down that an error was even being thrown before I tracked down where it was being swallowed.

This change uses process.nextTick to remove the callback from the promise.then call stack. I'm not sure if this is the best way to make sure the error gets reported. I'm not super familiar with promises but maybe it'd be better if an explicit error handler was registered on the promise and the error was re-thrown by that handler.

I also added a test using trycatch to make sure that the thrown error is reported up the stack as expected by a callback user.

Previously, if a synchronous error was thrown in the callback given to
toArray, the error is swallowed and never makes its way up the stack as
expected. This happens because the callback executes in a promise.then()
callback stack trace. The promise implementation catches the error and
doesn't report it other than via the "unhandledRejection" event. This is
unexpected for someone that is not otherwise using promises in their
application code.

This change uses process.nextTick to remove the callback from the
promise.then call stack.
@jonathanong
Copy link
Contributor

i think im ok with this. @dougwilson?

@dougwilson
Copy link
Member

LGTM

@jonathanong jonathanong self-assigned this Jan 13, 2016
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.

3 participants