Skip to content

Commit e090ccc

Browse files
JPeer264claude
andauthored
fix(gatsby): Fix errorHandler signature to match bundler-plugin-core API (#20048)
closes #20043 closes [JS-2024](https://linear.app/getsentry/issue/JS-2024/sentrygatsby-build-can-fail-with-typeerror-invokeerr-is-not-a-function) The `@sentry/bundler-plugin-core` was updated to call `errorHandler` with only a single `Error` argument, but the Gatsby plugin's `errorHandler` still expected two arguments `(err, invokeErr)`. This caused builds to fail with "TypeError: invokeErr is not a function" when a Sentry error occurred during source map upload. It was originally added in #4064, where we still had v1 of the `@senrty/webpack-plugin` (where the type still existed: https://github.com/getsentry/sentry-webpack-plugin/blob/cb854281eb409c5c14f6a0d1042429240644a48d/index.d.ts#L112). With v2, and the move to [our new repo](https://github.com/getsentry/sentry-javascript-bundler-plugins), this option got removed and is no longer part of it. So `invokeErr` is safe to remove, and should have been already with this PR #11292 Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent ad93ced commit e090ccc

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

packages/gatsby/gatsby-node.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ exports.onCreateWebpackConfig = ({ getConfig, actions }, options) => {
4141
},
4242
// Handle sentry-cli configuration errors when the user has not done it not to break
4343
// the build.
44-
errorHandler(err, invokeErr) {
44+
errorHandler(err) {
4545
const message = (err.message && err.message.toLowerCase()) || '';
4646
if (message.includes('organization slug is required') || message.includes('project slug is required')) {
4747
// eslint-disable-next-line no-console
@@ -55,7 +55,7 @@ exports.onCreateWebpackConfig = ({ getConfig, actions }, options) => {
5555
console.warn('Sentry [Warn]: Cannot upload source maps due to missing SENTRY_AUTH_TOKEN env variable.');
5656
return;
5757
}
58-
invokeErr(err);
58+
throw err;
5959
},
6060
}),
6161
],

packages/gatsby/test/gatsby-node.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,47 @@ describe('onCreateWebpackConfig', () => {
6565
expect(actions.setWebpackConfig).toHaveBeenCalledTimes(0);
6666
});
6767

68+
describe('errorHandler', () => {
69+
function getErrorHandler(): (err: Error) => void {
70+
const actions = { setWebpackConfig: vi.fn() };
71+
const getConfig = vi.fn().mockReturnValue({ devtool: 'source-map' });
72+
73+
onCreateWebpackConfig({ actions, getConfig }, {});
74+
75+
const pluginOptions = sentryWebpackPlugin.mock.calls[0][0];
76+
return pluginOptions.errorHandler;
77+
}
78+
79+
afterEach(() => {
80+
vi.clearAllMocks();
81+
});
82+
83+
it('accepts a single error argument (bundler-plugin-core v5 API)', () => {
84+
const errorHandler = getErrorHandler();
85+
expect(() => errorHandler(new Error('some error'))).toThrow('some error');
86+
});
87+
88+
it('does not throw for missing organization slug', () => {
89+
const errorHandler = getErrorHandler();
90+
expect(() => errorHandler(new Error('Organization slug is required'))).not.toThrow();
91+
});
92+
93+
it('does not throw for missing project slug', () => {
94+
const errorHandler = getErrorHandler();
95+
expect(() => errorHandler(new Error('Project slug is required'))).not.toThrow();
96+
});
97+
98+
it('does not throw for missing auth token', () => {
99+
const errorHandler = getErrorHandler();
100+
expect(() => errorHandler(new Error('Authentication credentials were not provided'))).not.toThrow();
101+
});
102+
103+
it('re-throws unknown errors', () => {
104+
const errorHandler = getErrorHandler();
105+
expect(() => errorHandler(new Error('Something unexpected'))).toThrow('Something unexpected');
106+
});
107+
});
108+
68109
describe('delete source maps after upload', () => {
69110
beforeEach(() => {
70111
vi.clearAllMocks();

0 commit comments

Comments
 (0)