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

[etk/error-reporting] Setup action hook callback to capture React Error Boundary exceptions #65503

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Sentry from '@sentry/browser';
import apiFetch from '@wordpress/api-fetch';
import { addAction } from '@wordpress/hooks';

const shouldActivateSentry = window.A8C_ETK_ErrorReporting_Config?.shouldActivateSentry === 'true';
/**
Expand All @@ -18,6 +19,12 @@ function activateSentry() {
release: 'wpcom-test-01',
} );

// Capture exceptions from Gutenberg React Error Boundaries
addAction( 'editor.ErrorBoundary.errorLogged', 'etk/error-reporting', ( error ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this work on Atomic if gutenberg is disabled? (I assume it would, as long as addAction doesn't crash everything if the action doesn't exist.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Atomic doesn't activate this module yet, but if it did, I don't see why it would crash -- if AT didn't have Gutenberg (and if the block editor still doesn't have the call to doAction) then the callback will just be registered here but never triggered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was that what you had in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think so, yeah. I was wondering what addAction does if the given "action type" doesn't exist

Copy link
Contributor

Choose a reason for hiding this comment

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

Since it's not loaded (I keep forgetting that!) I agree we don't need to worry about it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so, yeah. I was wondering what addAction does if the given "action type" doesn't exist

I don't think it implements such a check -- though I agree it'd be nice to double check, though! I'll check this out in the following days.

// error is the exception's error object
Sentry.captureException( error );
} );

// We still need to report the head errors, if any.
headErrors.forEach( ( error ) => Sentry.captureException( error ) );
Sentry.flush().then( () => delete window._jsErr );
Expand Down