From 221feb2cf527cc064c2b4de5608153e7325b13a3 Mon Sep 17 00:00:00 2001 From: Marcelo Serpa <81248+fullofcaffeine@users.noreply.github.com> Date: Tue, 12 Jul 2022 11:49:03 -0500 Subject: [PATCH] Setup action hook callback to capture React Error Boundary exceptions in Gutenberg with Sentry Register a callback to `editor.ErrorBoundary.errorLogged` action that will forward the error to Sentry everytime the action is called. The action has been added to all active React Error Boundaries in Gutenberg in the following changeset: https://github.com/WordPress/gutenberg/pull/42024 . --- .../editing-toolkit-plugin/error-reporting/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/editing-toolkit/editing-toolkit-plugin/error-reporting/index.js b/apps/editing-toolkit/editing-toolkit-plugin/error-reporting/index.js index ec3008d0e2475..51994a6d1144f 100644 --- a/apps/editing-toolkit/editing-toolkit-plugin/error-reporting/index.js +++ b/apps/editing-toolkit/editing-toolkit-plugin/error-reporting/index.js @@ -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'; /** @@ -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 ) => { + // 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 );