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

Error handling improvements #365

Merged

Conversation

ghiculescu
Copy link
Contributor

Proposing some changes that I mentioned here. To recap, I think the error logging in Stimulus is great, but several people (me included) have been caught by the fact that errors aren't reported elsewhere out of the box. The aim of this PR is to automatically integrate with third party error tracking services where possible, and to improve the documentation where not.

Specific changes:

  • If window.onerror is defined, Stimulus will now call it after logging an error. Many error tracking tools define this method, eg. Sentry, Airbrake.
  • Added documentation on how error handling works, including what happens out of the box and how to override it (with code sample from Add Application.prototype.handleError #53).
  • Added tests for the error handler.

@@ -1,7 +1,7 @@
import { ControllerTestCase } from "../cases/controller_test_case"
import { ClassController } from "../controllers/class_controller"

export default class ValueTests extends ControllerTestCase(ClassController) {
export default class ClassTests extends ControllerTestCase(ClassController) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change isn't related to this PR, it just fixes an incorrect class name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Fixed in main by caecf0f

@ghiculescu ghiculescu force-pushed the error-handling-tools-integration branch 6 times, most recently from e37a2be to 96256e4 Compare January 8, 2021 03:23
Base automatically changed from master to main January 12, 2021 20:57
@DaveSanders
Copy link

Any chance that this is going to be merged in? I just went down a 4 hour rabbit hole trying to figure out why Sentry wasn't getting called unless I explicitly called it. Now that I see this PR, I see what's happening, but man was it a long road to find this.

Copy link
Contributor

@sstephenson sstephenson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a much more friendly default 👍

docs/handbook/07_installing_stimulus.md Outdated Show resolved Hide resolved
packages/@stimulus/core/src/application.ts Outdated Show resolved Hide resolved
@@ -1,7 +1,7 @@
import { ControllerTestCase } from "../cases/controller_test_case"
import { ClassController } from "../controllers/class_controller"

export default class ValueTests extends ControllerTestCase(ClassController) {
export default class ClassTests extends ControllerTestCase(ClassController) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Fixed in main by caecf0f

Proposing some changes that I mentioned [here](hotwired#236 (comment)). To recap, I think the error logging in Stimulus is great, but several people (me included) have been caught by the fact that errors aren't reported elsewhere out of the box. The aim of this PR is to automatically integrate with third party error tracking services where possible, and to improve the documentation where not.

Specific changes:

- If `window.onerror` is defined, Stimulus will now call it after logging an error. Many error tracking tools define this method, eg. [Sentry](https://github.com/getsentry/sentry-javascript/blob/0ee07995d415d3870608c477cbdcf8445a51e1bb/packages/browser/src/loader.js#L192), [Airbrake](https://github.com/airbrake/airbrake-js/blob/9d4787b1c559aa39107d7288f46c4108c9a9d954/packages/browser/src/notifier.ts#L70)
- Added documentation on how error handling works, including what happens out of the box and how to override it (with code sample from hotwired#53)
- Added tests for the error handler.
@ghiculescu ghiculescu force-pushed the error-handling-tools-integration branch from 96256e4 to 0dcdfc4 Compare March 25, 2021 16:56
@ghiculescu
Copy link
Contributor Author

Thanks @sstephenson, made those fixes.

@sstephenson sstephenson merged commit 3bfd886 into hotwired:main Mar 25, 2021
@sstephenson
Copy link
Contributor

Fantastic!

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

Successfully merging this pull request may close these issues.

3 participants