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

feat(errors): sync/async error handling for lifecycle hooks and v-on handlers (#7653, #6953) #8395

Merged
merged 8 commits into from
Dec 20, 2018

Conversation

enkot
Copy link
Contributor

@enkot enkot commented Jun 21, 2018

Update:

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:

@coldino
Copy link

coldino commented Jun 26, 2018

Can we add error handling for v-on handlers to this? Both sync and async need to be caught for them.

I have working code and tests for this here: https://github.com/coldino/vue/commits/event-handler-errors. It would need very minor updates to work with the changes in this PR.

This will also address #6953.

@enkot
Copy link
Contributor Author

enkot commented Jun 27, 2018

@coldino
I think it will be great to address 2 issues in this PR. But what will be the proper way to merge changes? You can create pull request to this branch - "feature/async-errors-handling", and I will edit PR according to the changes from you ( for #6953 ).
P.S. or just create separate PR for #6953

@coldino
Copy link

coldino commented Jun 27, 2018

@enkot The changes will overlap significantly as I would switch to using your handlePromiseError function, so I will create a PR for your branch. Note that in addition to the ones you implemented, I also added async error handling for:

  • watcher callbacks
  • nextTick callbacks
  • invoked functions (v-on)
  • directive hooks

Currently there are only tests for the v-on invoked function async+sync errors. I don't have enough experience with the testing system to add tests for all of them. If you are able to assist with this we can have much greater coverage for async error catching.

I will keep the hooks without tests in a separate commit so you can include/exclude as you choose.

Improves the check for promise-like objects to ensure they are thenable.
Includes tests.
@coldino
Copy link

coldino commented Jun 27, 2018

I have only included the v-on checks in the PR as I didn't want to include changes with no tests and possibly delay this PR.

enkot and others added 2 commits June 30, 2018 16:30
@enkot enkot changed the title feat: add error handling for Promises / async (#7653) feat: add error handling for Promises / async (#7653, #6953) Jun 30, 2018
@enkot enkot changed the title feat: add error handling for Promises / async (#7653, #6953) feat: add sync/async error handling for lifecycle hooks and v-on handlers (#7653, #6953) Jun 30, 2018
@enkot enkot changed the title feat: add sync/async error handling for lifecycle hooks and v-on handlers (#7653, #6953) feat(errors): sync/async error handling for lifecycle hooks and v-on handlers (#7653, #6953) Jun 30, 2018
@vitormd

This comment has been minimized.

@yyx990803 yyx990803 changed the base branch from dev to 2.6 December 20, 2018 01:34
@humoyun91
Copy link

humoyun91 commented Oct 26, 2022

Does it support async methods which is called from hooks like created or mounted as most of the time one of the most common operations is to call some API to get some data from these hooks. Async methods which is bounded as event handlers are triggering errors as expected and errorCaptured is catching them but when the same async methods are called from created or mounted hooks, ErrorBoundary's errorCaptured is not catching anything. E.g., :

// LabelerAccount.vue
  mounted() {
    this.labelerInfo();
  },
  // ...
  async labelerInfo() {
    const response = await userInfo(this.userId);
  },


// Usage
<ErrorBoundary>
  <LabelerAccount />
</ErrorBoundary>

// `errorCaptured` hook of ErrorBoundary is not catching exceptions thrown from above usage

I checked it with Vue@2.7.10, it is not working

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

Successfully merging this pull request may close these issues.

6 participants