Skip to content

fix: Don't re-throw error in a setTimeout() #13613

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

Merged
merged 2 commits into from
Jun 11, 2019
Merged
Changes from all commits
Commits
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
14 changes: 10 additions & 4 deletions src/sentry/static/sentry/app/utils/errorHandler.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import RouteError from 'app/views/routeError';
export default function errorHandler(Component) {
class ErrorHandler extends React.Component {
static getDerivedStateFromError(error) {
setTimeout(() => {
throw error;
});

// Update state so the next render will show the fallback UI.
return {
hasError: true,
Expand All @@ -16,10 +12,20 @@ export default function errorHandler(Component) {
}

state = {
// we are explicit if an error has been thrown since errors thrown are not guaranteed
// to be truthy (e.g. throw null).
hasError: false,
error: null,
};

componentDidCatch(error, info) {
// eslint-disable-next-line no-console
console.error(
Copy link
Member Author

Choose a reason for hiding this comment

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

@billyvg looks like Sentry is outputting the stacktraces.

Just for completeness, I've console.error'd the component stacktrace here. see: https://reactjs.org/docs/error-boundaries.html#component-stack-traces

Looks like that PR you created recently will help with this: #13607 😄

'Component stack trace caught in <ErrorHandler />:',
info.componentStack
);
}

render() {
if (this.state.hasError) {
return <RouteError error={this.state.error} />;
Expand Down