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

Promise rejection in watcher not captured by Vue.config.errorHandler #11573

Closed
vvanpo opened this issue Aug 7, 2020 · 1 comment
Closed

Promise rejection in watcher not captured by Vue.config.errorHandler #11573

vvanpo opened this issue Aug 7, 2020 · 1 comment

Comments

@vvanpo
Copy link

vvanpo commented Aug 7, 2020

Version

2.6.11

Reproduction link

https://github.com/vvanpo/minimal-repros/tree/master/vue2

Steps to reproduce

Finding the same problem as posted here: #11035

See the minimal repro:

import Vue from 'vue/dist/vue.common.js'

test('errorHandler should capture promise rejections in watchers', () => {
  document.body.innerHTML = '<div id="#app"></div>'

  Vue.config.errorHandler = (err) => {
    console.log(err.toString())
  }

  new Vue({
    template: `<div />`,
    data: () => ({ foo: false, bar: false }),
    mounted() {
      this.foo = true
      this.bar = true
    },
    watch: {
      foo: async () => { throw new Error('foo') },
      bar: () => { throw new Error('bar') },
    },
  }).$mount(document.body.querySelector('#app'))
})

Results in the following:

(node:67048) UnhandledPromiseRejectionWarning: Error: foo
(node:67048) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:67048) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
 PASS  ./test.js
  ✓ errorHandler should capture promise rejections in watchers (19 ms)

  console.log
    Error: bar

      at _vueCommon.default.config.errorHandler (test.js:7:13)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.806 s
Ran all test suites.
✨  Done in 2.71s.

So you can see that it correctly captured the bar watcher's error, but not the promise rejection in foo.

What is expected?

Errors in async watchers can be caught by Vue.config.errorHandler.

What is actually happening?

Promise rejections inside async watchers are not caught by the errorHandler.

I've tested it in Vue 3, and there app.config.errorHandler captures all promise rejections as expected.

@posva
Copy link
Member

posva commented Aug 7, 2020

Duplicate of #10009

@posva posva closed this as completed Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants