Skip to content

Commit eb04258

Browse files
authored
fix(nextjs): Do not exit process when errors bubble up while additional uncaughtException-handlers are registered (#6138)
1 parent 3eaf71e commit eb04258

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

packages/nextjs/src/index.server.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ function addServerIntegrations(options: NextjsOptions): void {
118118
});
119119
integrations = addOrUpdateIntegration(defaultRewriteFramesIntegration, integrations);
120120

121+
const nativeBehaviourOnUncaughtException = new Integrations.OnUncaughtException();
122+
integrations = addOrUpdateIntegration(nativeBehaviourOnUncaughtException, integrations, {
123+
_options: { exitEvenIfOtherHandlersAreRegistered: false },
124+
});
125+
121126
if (hasTracingEnabled(options)) {
122127
const defaultHttpTracingIntegration = new Integrations.Http({ tracing: true });
123128
integrations = addOrUpdateIntegration(defaultHttpTracingIntegration, integrations, {

packages/node/src/integrations/onuncaughtexception.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { logAndExitProcess } from './utils/errorhandling';
77

88
type OnFatalErrorHandler = (firstError: Error, secondError?: Error) => void;
99

10+
// CAREFUL: Please think twice before updating the way _options looks because the Next.js SDK depends on it in `index.server.ts`
1011
interface OnUncaughtExceptionOptions {
1112
// TODO(v8): Evaluate whether we should switch the default behaviour here.
1213
// Also, we can evaluate using https://nodejs.org/api/process.html#event-uncaughtexceptionmonitor per default, and
@@ -48,6 +49,7 @@ export class OnUncaughtException implements Integration {
4849
*/
4950
public readonly handler: (error: Error) => void = this._makeErrorHandler();
5051

52+
// CAREFUL: Please think twice before updating the way _options looks because the Next.js SDK depends on it in `index.server.ts`
5153
private readonly _options: OnUncaughtExceptionOptions;
5254

5355
/**

0 commit comments

Comments
 (0)