-
-
Notifications
You must be signed in to change notification settings - Fork 33.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
fix(#9511): avoid promise catch multiple times #9526
Conversation
|
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.
Could you add a test case please?
I added a test case after your reminder, but I still don't know how to handle |
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.
I think the test should go with test/unit/features/error-handling.spec.js
According to my understanding of the bug, the test case under test/unit/features/error-handling.spec.js might look like this: it('config.errorHandler should capture async errors once', done => {
let times = 0
Vue.config.errorHandler = function () {
times++
}
Vue.component('error-div', {
mounted: function () {
this.$emit('error')
},
render: function (h) {
return h('div')
}
})
const vm = new Vue({
template: '<error-div @error="onError"></error-div>',
methods: {
onError: function() {
return Promise.reject(new Error('async error'))
}
}
}).$mount()
Vue.nextTick(() => {
expect(times).toBe(1)
done()
})
}) The above test case will result in nested calls, but there are no other similar scenes in Vue that will cause such nested calls, which I don't know. I think the above test case, other developers will look a bit confusing in the future, and in the The essential reason for this problem is that Promise is not used correctly. This problem is exposed when the method is nested, so I think it is more reasonable to write test cases for the method. If you still think that I should write test cases in test/unit/features/error-handling.spec.js, I will write the above test cases to this file and submit them again, or move the previously submitted test cases to this file. My native language is not English, so I need to use google translation often, I hope you can understand. And I am also submitting code to Vue for the first time, not very familiar with the project, thank you very much for your review. |
* fix(vuejs#9511): avoid promise catch multiple times * fix(vuejs#9511): add a test case for util/error/invokeWithErrorHandling * fix(vuejs#9511): update test case for util/error/invokeWithErrorHandling
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information:
fixed #9511
In some cases, invokeWithErrorHandling will have nested calls, and Promise will independently catch multiple times, resulting in multiple calls to handleError.
Look at a sample code:
The above code will output 1 and 2, but if you reassign the first catch call to p, it will not output 2.