Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/browser
SDK Version
6.19.7
Framework Version
No response
Link to Sentry event
No response
Reproduction Example/SDK Setup
No response
Steps to Reproduce
- use
ErrorBoundary in React project:
class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
// ......
componentDidCatch(error: Error, errorInfo: any) {
if (window.Sentry) {
window.Sentry.withScope(scope => {
Object.keys(errorInfo).forEach(key => {
scope.setExtra(key, errorInfo[key])
})
window.Sentry.captureException(error)
})
}
}
// ......
}
export default ErrorBoundary
- throw an error in the example component:
export const Example = () => {
useEffect(() => {
throw new Error('this is the error')
})
return <div>example</div>
}
Expected Result
ErrorBoundary catch the error and report it to the sentry platform with window.Sentry.captureException
Actual Result
window.Sentry.captureException didn't work and none of sentry requests sent. But when I added another window.Sentry.captureException outside the window.Sentry.withScope, it worked. Both of the captureException be executed.
componentDidCatch(error: Error, errorInfo: any) {
if (window.Sentry) {
window.Sentry.withScope(scope => {
Object.keys(errorInfo).forEach(key => {
scope.setExtra(key, errorInfo[key])
})
window.Sentry.captureException(error)
})
window.Sentry.captureException(new Error('error outside'))
}
}
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/browser
SDK Version
6.19.7
Framework Version
No response
Link to Sentry event
No response
Reproduction Example/SDK Setup
No response
Steps to Reproduce
ErrorBoundaryin React project:Expected Result
ErrorBoundarycatch the error and report it to the sentry platform withwindow.Sentry.captureExceptionActual Result
window.Sentry.captureExceptiondidn't work and none of sentry requests sent. But when I added anotherwindow.Sentry.captureExceptionoutside thewindow.Sentry.withScope, it worked. Both of thecaptureExceptionbe executed.