-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
Fixed issue where Promise rejection was hitting application #14816
Fixed issue where Promise rejection was hitting application #14816
Conversation
Deploy preview for element ready! Built with commit 8a2dbed |
What cause the rejection. Silently ignoring errors is a troublesome practice. Please find the source of error. |
What do you mean? This component is causing the rejection, intentionally.
In my case, it's an async process and so I have no choice but to return a rejected Promise. This component needs to catch it and ignore it, because it's not a real error. Using Promises in this way is anti-pattern, it would've been better to return a resolved Promise with either a |
Use, and keep comments in catchFn
|
The Promise rejection in this case is only used to determine whether the tab should change. I don't see the problem with catching it to ignore it. Here's a live example: https://jsfiddle.net/q9tdm3r6/ Try to switch tabs, then look at the console. You can see the unhandled Promise rejection. My point is, it should be possible to either return |
I know it is not ideal. But we can't change API unless it's a major version.
|
I understand the idea of catching to ignore an error. Let's look at this specific example: <el-tabs :before-leave="beforeLeave"> methods: {
async beforeLeave(activeName) {
if (activeName !== '0') throw new Error('prevent tab change');
}
} In this example, how would you prevent the tab change without resulting in an uncaught Promise rejection? I have to throw an error in order to prevent the tab change, it cannot be caught/ignored in my own code and still have the desired effect. At least, I haven't figured out a way to do this so far. |
I mean write your PR like this:
|
Ahh, sorry, I misunderstood. Will update in a bit! |
@wacky6 Updated. Good call on removing the |
…tion (ElemeFE#14816)" This reverts commit d1e0f98
Please make sure these boxes are checked before submitting your PR, thank you!
dev
branch.The uncaught rejection was bubbling up our application. And since we're using an error logger like Sentry, it was catching those and logging them. The error isn't really an error at all, so it needs to be caught and ignored in this case.