Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/core/observer/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
parsePath,
_Set as Set,
handleError,
invokeWithErrorHandling,
noop
} from '../util/index'

Expand Down Expand Up @@ -191,11 +192,7 @@ export default class Watcher {
const oldValue = this.value
this.value = value
if (this.user) {
try {
this.cb.call(this.vm, value, oldValue)
} catch (e) {
handleError(e, this.vm, `callback for watcher "${this.expression}"`)
}
invokeWithErrorHandling(this.cb, this.vm, [value, oldValue], this.vm, ("callback for watcher \"" + (this.expression) + "\""))
} else {
this.cb.call(this.vm, value, oldValue)
}
Expand Down
22 changes: 22 additions & 0 deletions test/unit/features/error-handling.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ describe('Error handling', () => {
}).then(done)
})

it('should recover from errors in user watcher from promise error', done => {
const vm = createTestInstance(components.userWatcherPromise)
vm.n++
setTimeout(() => {
expect(`Error in callback for watcher "n" (Promise/async)`).toHaveBeenWarned()
expect(`Error: userWatcherPromise error`).toHaveBeenWarned()
assertBothInstancesActive(vm).then(done)
})
})

it('should recover from errors in user immediate watcher callback', done => {
const vm = createTestInstance(components.userImmediateWatcherCallback)
waitForUpdate(() => {
Expand Down Expand Up @@ -344,6 +354,18 @@ function createErrorTestComponents () {
}
}

components.userWatcherPromise = {
props: ['n'],
watch: {
n () {
return new Promise((resolve, reject) => reject(new Error('userWatcherPromise error')))
}
},
render (h) {
return h('div', this.n)
}
}

components.userImmediateWatcherCallback = {
props: ['n'],
watch: {
Expand Down