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

Add handleError during event handling #5709

Merged
merged 2 commits into from
May 29, 2017

Conversation

chrisnicola
Copy link
Contributor

Currently handleError is used to handle errors during lifecycle hooks and component rendering. This handles most errors thrown by the component however event handlers are not handled. So a component like:

<template>
  <button @click="error()">I Throw Errors</button>
</template>

<script>
  {
    methods: {
      error() { throw new Error('thrown!'); }
    }
  }
</script>

Will simple throw an error and the error will never be passed to handleError nor is one able to use Vue.config.errorHandler for error reporting. For my specific use case I wanted to make sure that the plugin I use to report errors to Honeybadger would catch and report errors in event handlers, but more generally any error reporting that relies on errorHandler will require this.

It makes sense to me that, for consistency, Vue would want to handle errors in event handlers the same way as is done lifecycle hooks and rendering. This is consistent with the changes requested and completed in #5198 and #4370.

As this is my first PR, I hope these changes are up to the code standard for the project, but if there is anything else needed just let me know and I'll fix it.

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:

While it is unlikely any running apps would have depended on this behaviour. This introduces a change which will result in exceptions thrown by event handlers to be handled by handleError and any function assigned to Vue.config.errorHandler. Since errors are not re-thrown by handleError any code that was depending on errors in events not being handled could theoretically break. I thought it would be worthwhile to note this.

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:

Currently handleError is used to handle errors during lifecycle hooks.
This commit adds this functionality in to the event handling for
consistency.
@chrisnicola chrisnicola force-pushed the add-error-handling-to-events branch from 3e63ba1 to ded4a13 Compare May 19, 2017 20:59
@yyx990803 yyx990803 merged commit 11b7d5d into vuejs:dev May 29, 2017
@chrisnicola chrisnicola deleted the add-error-handling-to-events branch May 29, 2017 16:09
@krimeshu
Copy link

krimeshu commented Jul 30, 2017

Vue.config.errorHandler not working in this situation:

https://jsfiddle.net/50wL7mdz/50200/

And although error event handler captured the error, but still cannot get the detail information.

Need help~

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

Successfully merging this pull request may close these issues.

3 participants