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

promise chains and the bizarre consequence of registering a handler with Ember.onerror #15864

Closed
kbullaughey opened this issue Nov 20, 2017 · 2 comments

Comments

@kbullaughey
Copy link

It seems that when upgrading from 2.13 to 2.16 the effect of registering a global error handler using Ember.onerror has changed how promise chains are handled.

I have been using a pattern of handling errors in long promise chains that involves having step-specific reject handlers. Each of these handlers would be responsible for handling any errors in the previous step. Additionally, these handlers would continue rejecting all the way down the chain so that even if an error is handled, none of the rest of the chain is executed.

Unfortunately, this pattern seems not to be possible now when registering an error handler with Ember.onerror. The example in the Guides suggests that Ember.onerror can be used for logging errors. I would have expected that whether one registeres an error handler with Ember.onerror shouldn't affect which methods are called in the promise chain. However, in 2.16 this seems to be the case.

I illustrate this behavior in an example repo.

In the file app/controllers/application.js there is a boolean variable registerGlobalHandler that can be toggled to determine if a global error handler using Ember.onerror is registered.

When registerGlobalHandler is set to false, I get the expected behavior:

problem in step 2: Error: step 1 error handler failed
rsvp error: reraise

When registerGlobalHandler is set to true, the promise chain is continued, despite the error thrown in step1Problem, which is a reject handler passed to then.

In this case, the output looks like this:

global error handler: Error: step 1 error handler failed
step 3
success

This behavior is quite problematic because it means that the chain will continue if there is an exception thrown in the reject handler. Also, it's bizarre that this behavior is contingent on whether a handler was registered with Ember.onerror.

@kbullaughey
Copy link
Author

I was able to reproduce the 2.13 behavior by starting with what's currently in the ember.js master branch (a 2.17 beta) and downgrading backburner to 0.4.0. I haven't yet worked out what changed in backburner to cause this problem.

@rwjblue
Copy link
Member

rwjblue commented Nov 23, 2017

After reviewing all the wonderful research @kbullaughey did here (and in BackburnerJS/backburner.js#274) along with a lengthy pairing session with @hjdivad, I believe that BackburnerJS/backburner.js#277 fixes the issue and explains exactly what is happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants