Skip to content

Commit c04cf80

Browse files
committed
fix(nextjs): Check for invalid tunnel option on server
If the tunnel option will cause an error to be thrown, catch it, and re-throw with a better error message. Fixes GH-6381
1 parent 36488ec commit c04cf80

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

packages/nextjs/src/index.server.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ export function init(options: NextjsOptions): void {
7979
const activeDomain = domain.active;
8080
domain.active = null;
8181

82+
if (typeof options.tunnel !== 'undefined') {
83+
try {
84+
new URL(options.tunnel);
85+
} catch (error) {
86+
__DEBUG_BUILD__ &&
87+
logger.error('The tunnel option is not a valid URL. It must be a full URL including the protocol.');
88+
throw new Error('The tunnel option is not a valid URL. It must be a full URL including the protocol.');
89+
}
90+
}
8291
nodeInit(options);
8392

8493
const filterTransactions: EventProcessor = event => {

packages/nextjs/test/index.server.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,24 @@ describe('Server init()', () => {
139139
});
140140
});
141141

142+
it('should not fail on valid tunnel option', () => {
143+
expect(() =>
144+
init({
145+
dsn: 'https://[email protected]/12312012',
146+
tunnel: 'https://example.com/api',
147+
}),
148+
).not.toThrowError();
149+
});
150+
151+
it('should fail on invalid tunnel option', () => {
152+
expect(() =>
153+
init({
154+
dsn: 'https://[email protected]/12312012',
155+
tunnel: '/invalid',
156+
}),
157+
).toThrowError('The tunnel option is not a valid URL. It must be a full URL including the protocol.');
158+
});
159+
142160
describe('integrations', () => {
143161
// Options passed by `@sentry/nextjs`'s `init` to `@sentry/node`'s `init` after modifying them
144162
type ModifiedInitOptions = { integrations: Integration[] };

0 commit comments

Comments
 (0)