From b12d142702c7c4f5303174e635953e68c908356e Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Tue, 24 Jun 2025 14:56:31 +0200 Subject: [PATCH] expose top level errorHandler option --- packages/nextjs/src/config/types.ts | 17 +++++++++++++++++ .../nextjs/src/config/webpackPluginOptions.ts | 1 + .../config/webpack/webpackPluginOptions.test.ts | 17 +++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/packages/nextjs/src/config/types.ts b/packages/nextjs/src/config/types.ts index fe05624ba15e..e8172efea72e 100644 --- a/packages/nextjs/src/config/types.ts +++ b/packages/nextjs/src/config/types.ts @@ -445,6 +445,23 @@ export type SentryBuildOptions = { */ automaticVercelMonitors?: boolean; + /** + * When an error occurs during release creation or sourcemaps upload, the plugin will call this function. + * + * By default, the plugin will simply throw an error, thereby stopping the bundling process. + * If an `errorHandler` callback is provided, compilation will continue, unless an error is + * thrown in the provided callback. + * + * To allow compilation to continue but still emit a warning, set this option to the following: + * + * ```js + * (err) => { + * console.warn(err); + * } + * ``` + */ + errorHandler?: (err: Error) => void; + /** * Contains a set of experimental flags that might change in future releases. These flags enable * features that are still in development and may be modified, renamed, or removed without notice. diff --git a/packages/nextjs/src/config/webpackPluginOptions.ts b/packages/nextjs/src/config/webpackPluginOptions.ts index 641efd77524c..f4ff4363cdb7 100644 --- a/packages/nextjs/src/config/webpackPluginOptions.ts +++ b/packages/nextjs/src/config/webpackPluginOptions.ts @@ -62,6 +62,7 @@ export function getWebpackPluginOptions( project: sentryBuildOptions.project, telemetry: sentryBuildOptions.telemetry, debug: sentryBuildOptions.debug, + errorHandler: sentryBuildOptions.errorHandler, reactComponentAnnotation: { ...sentryBuildOptions.reactComponentAnnotation, ...sentryBuildOptions.unstable_sentryWebpackPluginOptions?.reactComponentAnnotation, diff --git a/packages/nextjs/test/config/webpack/webpackPluginOptions.test.ts b/packages/nextjs/test/config/webpack/webpackPluginOptions.test.ts index 76ab58be9b64..e95ab5c82bf8 100644 --- a/packages/nextjs/test/config/webpack/webpackPluginOptions.test.ts +++ b/packages/nextjs/test/config/webpack/webpackPluginOptions.test.ts @@ -138,6 +138,23 @@ describe('getWebpackPluginOptions()', () => { }); }); + it('forwards errorHandler option', () => { + const buildContext = generateBuildContext({ isServer: false }); + const mockErrorHandler = (err: Error) => { + throw err; + }; + + const generatedPluginOptions = getWebpackPluginOptions( + buildContext, + { + errorHandler: mockErrorHandler, + }, + undefined, + ); + + expect(generatedPluginOptions.errorHandler).toBe(mockErrorHandler); + }); + it('returns the right `assets` and `ignore` values during the server build', () => { const buildContext = generateBuildContext({ isServer: true }); const generatedPluginOptions = getWebpackPluginOptions(buildContext, {}, undefined);