From e37e6e7c2ac7dc33f9eb33a8db3163e974a72bf8 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 21 Mar 2023 18:43:35 +0100 Subject: [PATCH 1/3] feat(react): Handle case where error.cause already defined --- packages/react/src/errorboundary.tsx | 9 +++- packages/react/test/errorboundary.test.tsx | 62 ++++++++++++++++++---- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/packages/react/src/errorboundary.tsx b/packages/react/src/errorboundary.tsx index 1553028195a2..d7312fdeffbb 100644 --- a/packages/react/src/errorboundary.tsx +++ b/packages/react/src/errorboundary.tsx @@ -66,6 +66,13 @@ const INITIAL_STATE = { eventId: null, }; +function setCause(error: Error & { cause?: Error }, cause: Error): void { + if (error.cause) { + return setCause(error.cause, cause); + } + error.cause = cause; +} + /** * A ErrorBoundary component that logs errors to Sentry. Requires React >= 16. * NOTE: If you are a Sentry user, and you are seeing this stack frame, it means the @@ -93,7 +100,7 @@ class ErrorBoundary extends React.Component; } -const TestApp: React.FC = ({ children, ...props }) => { +interface TestAppProps extends ErrorBoundaryProps { + errorComp?: JSX.Element; +} + +const TestApp: React.FC = ({ children, errorComp, ...props }) => { + // eslint-disable-next-line no-param-reassign + const customErrorComp = errorComp || ; const [isError, setError] = React.useState(false); return ( = ({ children, ...props }) => { } }} > - {isError ? : children} + {isError ? customErrorComp : children}