-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Safe Apollo Reducers that can't crash the store #874
Conversation
@helfer here it is finally! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is neat, thanks a lot! Do you think you could come up with a test that breaks the resolvers and exercises the code in the catch block? If not, I think we should add a console.warn statement so that it's possible to debug these errors (otherwise they will essentially be silently swallowed).
It would also be useful to have at least one example of something that this code helps fix in the wild. I know it's good for stability, but we also have to worry about debuggability, and right now I'm leaning a bit more towards debuggability.
@rricard let me know if you have time to take another look at this. I would really like to merge it for the 0.6 release which will be in the next few days. |
@helfer can that wait the week end ? or I can try to take a look tonight if 0.6 is really coming soon ... |
But I agree, I have to find some way to ensure it will not swallow errors |
@rricard by the weekend is fine, no rush! |
We prevent throwing inside the reducer by wrapping it in a try/catch block. The error will still be reported to the user.
Ensure the error is catched and not swallowed Ensure redux is able to carry on after the error
@helfer: so the main uses I had of this catcher are now gone since the legacy diffing is gone. So I had to find an another way to trigger a throw in the reducer. What I test here works, moreover I ensure the error is not swallowed. |
So for me this error catcher shouldn't be triggered once but when it does, that means something is going wrong in Apollo, an error is likely to be uncatched. And in this case, even if something is really wrong, that doesn't mean we should let redux crash. So I would be for adding a big warning in the console printing the stacktrace asking for the user to open up a bug report about it if the reducer crashes. Note that a reducer crash can happen if we |
@rricard awesome! Once you add the warning, we're good to merge here. |
@rricard I just tried adding a warning, which made me realize that errors that are not Apollo Client internal errors are actually possible in the reducers, which means that the error is more likely due to code that the user wrote than due to code that we wrote. Concrete examples:
For that reason I will not add a warning and simply merge the PR as it is now 🎉 |
@helfer oh ok, didn't see this one but you're right! Thanks! I was going to handle that this WE but glad you took a look before ;) |
TODO:
We prevent throwing inside the reducer by wrapping it in a try/catch block. The error will still be reported to the user.