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

Immediate watcher skips parent(s) errorCaptured and jumps straight to the top error handler #8567

Closed
michaelfelixmurphy opened this issue Jul 27, 2018 · 0 comments · Fixed by #8581

Comments

@michaelfelixmurphy
Copy link

Version

2.5.16

Reproduction link

https://codesandbox.io/s/wkpy6x5r25

Steps to reproduce

Simply opening and running the sandbox should show the error. Instead of getting an alert that App.vue caught the error in HelloWorld's watcher, the error escapes all the way to the top level. To see the expected behavior, open Hello World and set the watcher to immediate: false. Then hit the button to trigger the watcher. In this case the error is caught by the parent, App.vue. In the immediate case, this does not happen.

What is expected?

Errors in immediate watchers should be caught by the parent component(s)'s errorCaptured().

What is actually happening?

The error escapes to the nextTick hander. This handler has no ctx or vm to pass to the errorHandler. When errorHandler does not receive a vm, it cannot call the parent errorCaptured handlers.


This appears to be an oversight in src/core/instance/state.js. In the case options.immediate is true, cb.call(vm, watcher.value) should be wrapped in a try catch that explicitly calls handleError with the vm.

A proposed fix:

    if (options.immediate) {
      try {
        cb.call(vm, watcher.value)
      } catch (e) {
        handleError(e, vm, `immediate call for watcher ${watcher.expression}`)
      }
    }
yyx990803 pushed a commit that referenced this issue Nov 29, 2018
)

The handle callback call should be wrapped in a try/catch that explicitly calls handleError

fix #8567
f2009 pushed a commit to f2009/vue that referenced this issue Jan 25, 2019
…ejs#8581)

The handle callback call should be wrapped in a try/catch that explicitly calls handleError

fix vuejs#8567
aJean pushed a commit to aJean/vue that referenced this issue Aug 19, 2020
…ejs#8581)

The handle callback call should be wrapped in a try/catch that explicitly calls handleError

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

Successfully merging a pull request may close this issue.

2 participants