Skip to content

Commit c2261ad

Browse files
authored
feat(js): Add React ErrorBoundary componentStack to errors (#37372)
Make use of React 17+ Native Component Stack errors and attach them to errors being captured by Sentry. This should provide a more useful stacktrace when trying to debug these issues.
1 parent cd457a6 commit c2261ad

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

static/app/components/errorBoundary.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ class ErrorBoundary extends Component<Props, State> {
6262
Object.keys(errorTag).forEach(tag => scope.setTag(tag, errorTag[tag]));
6363
}
6464

65+
// Based on https://github.com/getsentry/sentry-javascript/blob/6f4ad562c469f546f1098136b65583309d03487b/packages/react/src/errorboundary.tsx#L75-L85
66+
const errorBoundaryError = new Error(error.message);
67+
errorBoundaryError.name = `React ErrorBoundary ${errorBoundaryError.name}`;
68+
errorBoundaryError.stack = errorInfo.componentStack;
69+
70+
error.cause = errorBoundaryError;
71+
6572
scope.setExtra('errorInfo', errorInfo);
6673
Sentry.captureException(error);
6774
});

0 commit comments

Comments
 (0)