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

fix(nextjs): Do not exit process when errors bubble up while additional uncaughtException-handlers are registered #6138

Merged
merged 10 commits into from Nov 4, 2022

Conversation

lforst
Copy link
Member

@lforst lforst commented Nov 4, 2022

This PR updates the Next.js SDK so that it won't quit the Next.js server when an error bubbles up to global scope while there are additional uncaughtException handlers registered (e.g. by Next.js itself when middleware is provided).

It uses an option introduced in #6137.

…o lforst-fix-nextjs-quitting-on-aborted-requests
@lforst lforst changed the base branch from master to lforst-mimic-native-behaviour-onuncaught-exception November 4, 2022 14:00
Comment on lines 122 to 124
integrations = addOrUpdateIntegration(nativeBehaviourOnUncaughtException, integrations, {
_options: { exitEvenWhenOtherOnUncaughtExceptionHandlersAreRegistered: false },
});
Copy link
Member Author

Choose a reason for hiding this comment

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

I actually really don't like this. Seems very fragile.

Copy link
Member

Choose a reason for hiding this comment

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

It's a little hacky, it's true. It predates my work a few months ago cleaning up how default integrations interact with custom ones, and I thought about changing it then, but I couldn't come up with a better solution to the problem of sometimes needing to merge our default options with user-provided options in the same integration, and sometimes needing to force certain integrations to be there even if the user has overridden the other defaults, without changing the entire system.

If you have a good idea here, I'm all ears. That said, if we have the right tests in place, any changes to the underlying integration class's options should cause the tests to fail, so I don't think it's actually that brittle as long as we're testing well.

Copy link
Member

@mydea mydea left a comment

Choose a reason for hiding this comment

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

LGTM! The coupling to _options is not ideal but IMHO ok for this purpose.

lforst added a commit that referenced this pull request Nov 4, 2022
Base automatically changed from lforst-mimic-native-behaviour-onuncaught-exception to master November 4, 2022 14:47
@lforst lforst merged commit eb04258 into master Nov 4, 2022
@lforst lforst deleted the lforst-fix-nextjs-quitting-on-aborted-requests branch November 4, 2022 15:13
Comment on lines +121 to +124
const nativeBehaviourOnUncaughtException = new Integrations.OnUncaughtException();
integrations = addOrUpdateIntegration(nativeBehaviourOnUncaughtException, integrations, {
_options: { exitEvenIfOtherHandlersAreRegistered: false },
});
Copy link
Member

Choose a reason for hiding this comment

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

I'm a little confused by this. The point of addOrUpdateIntegration is to say, "here's the integration to add if no instance is already there, but if an instance is there, update it with these options." This means that the integration to add should have the same options as the the ones which are being updated.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I assumed the options didn't matter since the UncaughtException integration is part of the default integrations anyways but you're right - we should add the options in case the users override the integration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants