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 error boundary components and exception logging #6655

Merged
merged 32 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
76eabd4
Update Gutenberg ref
fluiddot Feb 20, 2024
b753732
Add error logging setup
fluiddot Feb 20, 2024
24f4aa0
Update Gutenberg ref
fluiddot Feb 22, 2024
ae8851c
Add bundle and source map files to gitignore
fluiddot Feb 22, 2024
4556a29
Include source map when generating the xcframework
fluiddot Feb 22, 2024
2afe0f4
Update Gutenberg ref
fluiddot Feb 22, 2024
6fd1862
Upload source map artifact during JS bundle generation
fluiddot Feb 22, 2024
b3db684
Update Gutenberg ref
fluiddot Feb 23, 2024
ecb8b0a
Trigger default error handler after sending an unhandled JS exception
fluiddot Feb 23, 2024
19d9b7f
Call default error handler only after the exception is sent
fluiddot Feb 23, 2024
d883dd2
Update Gutenberg ref
fluiddot Feb 26, 2024
d0b3119
Merge branch 'trunk' into add/error-boundary
fluiddot Feb 26, 2024
6a50374
Generate composed source map after creating bundles
fluiddot Feb 26, 2024
815fd89
Update Gutenberg ref
fluiddot Feb 27, 2024
61ba344
Mark exceptions detected by error handler as unhandled
fluiddot Feb 27, 2024
6bd6d87
Update Gutenberg ref
fluiddot Feb 27, 2024
2640b6d
Limit exception logging to fatal errors
fluiddot Feb 27, 2024
3785095
Update Gutenberg ref
fluiddot Feb 27, 2024
0003382
Update Gutenberg ref
fluiddot Feb 27, 2024
556f6ad
Update Gutenberg ref
fluiddot Feb 27, 2024
cdf9bfd
Update Gutenberg ref
fluiddot Feb 28, 2024
6fdcd61
Merge branch 'trunk' into add/error-boundary
fluiddot Feb 28, 2024
f1698d6
Include source map to Android assets
fluiddot Feb 28, 2024
c06df89
Update Gutenberg ref
fluiddot Feb 29, 2024
32e5e93
Update Gutenberg ref
fluiddot Feb 29, 2024
a88a073
Update Gutenberg ref
fluiddot Feb 29, 2024
db21bd3
Merge branch 'trunk' into add/error-boundary
fluiddot Mar 6, 2024
3b6fab2
build: Update Gutenberg ref
fluiddot Mar 6, 2024
585cc17
Update release notes
fluiddot Mar 6, 2024
39749cc
build: Update Gutenberg ref
fluiddot Mar 6, 2024
46d7600
Update Gutenberg ref
fluiddot Mar 7, 2024
1e665f9
Update Gutenberg ref with merge commit
fluiddot Mar 11, 2024
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
Expand Up @@ -5,6 +5,7 @@ set -euo pipefail
# Retrieve data from previous steps
PUBLISHED_AZTEC_VERSION=`buildkite-agent meta-data get "PUBLISHED_REACT_NATIVE_AZTEC_ANDROID_VERSION"`
buildkite-agent artifact download bundle/android/App.js .
buildkite-agent artifact download bundle/android/App.composed.js.map .

# Copy the JavaScript bundle and all local static assets referenced within the
# bundle to the appropriate locations for inclusion in the bridge bundle
Expand Down
1 change: 1 addition & 0 deletions .buildkite/commands/publish-react-native-ios-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

echo "--- :arrow_down: Download iOS JS bundle"
buildkite-agent artifact download bundle/ios/App.js .
buildkite-agent artifact download bundle/ios/App.composed.js.map .
buildkite-agent artifact download ios-assets.tar.gz .
mkdir -p ios-xcframework/Gutenberg/Resources
tar -xzvf ios-assets.tar.gz -C ios-xcframework/Gutenberg/Resources/
Expand Down
18 changes: 4 additions & 14 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,29 +143,19 @@ steps:
echo "--- :android: Build Android bundle"
npm run bundle:android

echo "--- :arrow_up: Upload Android bundle artifact"
echo "--- :arrow_up: Upload Android bundle and source map artifacts"
buildkite-agent artifact upload bundle/android/App.js

if [[ -n "$BUILDKITE_TAG" ]]; then
echo "--- :arrow_up: Upload Android source map"
node gutenberg/node_modules/react-native/scripts/compose-source-maps.js bundle/android/App.text.js.map bundle/android/App.js.map -o bundle/android/App.composed.js.map
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The composed source map is now generated as part of the bundle npm command.

buildkite-agent artifact upload bundle/android/App.composed.js.map
fi
buildkite-agent artifact upload bundle/android/App.composed.js.map

echo "--- :ios: Build iOS bundle"
npm run bundle:ios

echo "--- :arrow_up: Upload iOS bundle artifact"
echo "--- :arrow_up: Upload iOS bundle and source map artifacts"
buildkite-agent artifact upload bundle/ios/App.js
buildkite-agent artifact upload bundle/ios/App.composed.js.map
tar -czvf ios-assets.tar.gz -C ios-xcframework/Gutenberg/Resources assets/
buildkite-agent artifact upload ios-assets.tar.gz

if [[ -n "$BUILDKITE_TAG" ]]; then
echo "--- :arrow_up: Upload iOS source map"
node gutenberg/node_modules/react-native/scripts/compose-source-maps.js bundle/ios/App.text.js.map bundle/ios/App.js.map -o bundle/ios/App.composed.js.map
buildkite-agent artifact upload bundle/ios/App.composed.js.map
fi

- label: "Build Android RN Aztec & Publish to S3"
depends_on:
- lint
Expand Down
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ gen/
build/
build.log
bundle/android/raw/*
bundle/android/App.js
bundle/android/App.js.map
bundle/android/App.text.js
bundle/android/App.text.js.map
bundle/android/App.*
bundle/ios/App.*
bundle/ios/assets/gutenberg/packages/block-library/src/*

Expand Down
2 changes: 1 addition & 1 deletion gutenberg
Submodule gutenberg updated 410 files
4 changes: 4 additions & 0 deletions ios-xcframework/XCFrameworkScaffold.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
1D9EA4BE2B87A2570086B30F /* App.composed.js.map in Resources */ = {isa = PBXBuildFile; fileRef = 1D9EA4BD2B87A2470086B30F /* App.composed.js.map */; };
2F4F38292B86842C006EF573 /* external-style-overrides.css in Resources */ = {isa = PBXBuildFile; fileRef = 2F4F38282B86842C006EF573 /* external-style-overrides.css */; };
2F4F382B2B86844A006EF573 /* extra-localstorage-entries.js in Resources */ = {isa = PBXBuildFile; fileRef = 2F4F382A2B86844A006EF573 /* extra-localstorage-entries.js */; };
2F4F382D2B868457006EF573 /* remove-nux.js in Resources */ = {isa = PBXBuildFile; fileRef = 2F4F382C2B868457006EF573 /* remove-nux.js */; };
Expand Down Expand Up @@ -42,6 +43,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
1D9EA4BD2B87A2470086B30F /* App.composed.js.map */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; name = App.composed.js.map; path = ../../../bundle/ios/App.composed.js.map; sourceTree = "<group>"; };
2F4F38282B86842C006EF573 /* external-style-overrides.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; name = "external-style-overrides.css"; path = "../../../resources/unsupported-block-editor/external-style-overrides.css"; sourceTree = "<group>"; };
2F4F382A2B86844A006EF573 /* extra-localstorage-entries.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = "extra-localstorage-entries.js"; path = "../../../resources/unsupported-block-editor/extra-localstorage-entries.js"; sourceTree = "<group>"; };
2F4F382C2B868457006EF573 /* remove-nux.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = "remove-nux.js"; path = "../../../resources/unsupported-block-editor/remove-nux.js"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -99,6 +101,7 @@
2F4F382A2B86844A006EF573 /* extra-localstorage-entries.js */,
2F4F38282B86842C006EF573 /* external-style-overrides.css */,
3FA0C5802A1C8C9700600A9A /* App.js */,
1D9EA4BD2B87A2470086B30F /* App.composed.js.map */,
3F12363F29F6B21300AF54A4 /* content-functions.js */,
3F12364429F6B21300AF54A4 /* editor-behavior-overrides.js */,
3F12363D29F6B21300AF54A4 /* editor-style-overrides.css */,
Expand Down Expand Up @@ -273,6 +276,7 @@
3F12364C29F6B21300AF54A4 /* wp-bar-override.css in Resources */,
3F12365029F6B23300AF54A4 /* supported-blocks.json in Resources */,
3FA0C5812A1C8C9700600A9A /* App.js in Resources */,
1D9EA4BE2B87A2570086B30F /* App.composed.js.map in Resources */,
2F4F38292B86842C006EF573 /* external-style-overrides.css in Resources */,
3F12364729F6B21300AF54A4 /* insert-block.js in Resources */,
);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
"bundle": "npm run clean && npm run bundle:js",
"prebundle:js": "npm run i18n:update",
"bundle:js": "npm run bundle:android && npm run bundle:ios",
"bundle:android": "npm run bundle:android:text && npm run bundle:android:bytecode",
"bundle:android": "npm run bundle:android:text && npm run bundle:android:bytecode && node gutenberg/node_modules/react-native/scripts/compose-source-maps.js bundle/android/App.text.js.map bundle/android/App.js.map -o bundle/android/App.composed.js.map",
"bundle:android:text": "mkdir -p bundle/android && npm run rn-bundle -- --platform android --dev false --entry-file ./index.js --assets-dest ./bundle/android --bundle-output ./bundle/android/App.text.js --sourcemap-output ./bundle/android/App.text.js.map",
"bundle:android:bytecode": "./gutenberg/node_modules/react-native/sdks/hermesc/`node -e \"const platform=require('os').platform();console.log(platform === 'darwin' ? 'osx-bin' : (platform === 'linux' ? 'linux64-bin' : (platform === 'win32' ? 'win64-bin' : 'unsupported-os')));\"`/hermesc -emit-binary -O -out bundle/android/App.js bundle/android/App.text.js -output-source-map",
"bundle:ios": "npm run bundle:ios:text && npm run bundle:ios:bytecode",
"bundle:ios": "npm run bundle:ios:text && npm run bundle:ios:bytecode && node gutenberg/node_modules/react-native/scripts/compose-source-maps.js bundle/ios/App.text.js.map bundle/ios/App.js.map -o bundle/ios/App.composed.js.map",
"bundle:ios:text": "mkdir -p bundle/ios && npm run rn-bundle -- --platform ios --dev false --entry-file ./index.js --assets-dest ./ios-xcframework/Gutenberg/Resources --bundle-output ./bundle/ios/App.text.js --sourcemap-output ./bundle/ios/App.text.js.map",
"bundle:ios:bytecode": "./gutenberg/node_modules/react-native/sdks/hermesc/`node -e \"const platform=require('os').platform();console.log(platform === 'darwin' ? 'osx-bin' : (platform === 'linux' ? 'linux64-bin' : (platform === 'win32' ? 'win64-bin' : 'unsupported-os')));\"`/hermesc -emit-binary -O -out bundle/ios/App.js bundle/ios/App.text.js -output-source-map",
"prewpandroid": "rm -Rf $TMPDIR/gbmobile-wpandroidfakernroot && mkdir $TMPDIR/gbmobile-wpandroidfakernroot && ln -s $(cd \"$(dirname \"../../../\")\"; pwd) $TMPDIR/gbmobile-wpandroidfakernroot/android",
Expand Down
37 changes: 37 additions & 0 deletions src/errorLogging/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* WordPress dependencies
*/
import { logException } from '@wordpress/react-native-bridge';

// Setting Error handler to send exception. This implemenetation is based on Sentry React Native SDK:
// https://github.com/getsentry/sentry-react-native/blob/adfb66f16438dfd98f280307844778c7291b584b/src/js/integrations/reactnativeerrorhandlers.ts#L187-L262
export default () => {
const errorUtils = global.ErrorUtils;
const defaultHandler =
errorUtils.getGlobalHandler && errorUtils.getGlobalHandler();

let handlingFatal = false;
errorUtils.setGlobalHandler( ( error, isFatal ) => {
// We want to handle fatals, but only in production mode.
const shouldHandleFatal = isFatal && ! __DEV__;
if ( shouldHandleFatal ) {
if ( handlingFatal ) {
// eslint-disable-next-line no-console
console.warn(
'Encountered multiple fatals in a row. The latest:',
error
);
return;
}
handlingFatal = true;
}

// TODO: Set severity and exception mechanism.
// https://github.com/getsentry/sentry-react-native/blob/adfb66f16438dfd98f280307844778c7291b584b/src/js/integrations/reactnativeerrorhandlers.ts#L235-L239
fluiddot marked this conversation as resolved.
Show resolved Hide resolved

logException( error, {}, () => {
// Wait for the exception to be sent to host app.
defaultHandler( error, isFatal );
} );
} );
};
2 changes: 2 additions & 0 deletions src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { initialHtmlGutenberg } from '@wordpress/react-native-editor';
*/
import initialHtml from './initial-html';
import initAnalytics from './analytics';
import initErrorLogging from './errorLogging';

const setupHooks = () => {
// Hook triggered before the editor is rendered
Expand Down Expand Up @@ -75,4 +76,5 @@ const setupHooks = () => {
export default () => {
initAnalytics();
setupHooks();
initErrorLogging();
};