Skip to content

Commit 034fd7b

Browse files
committed
- move tunnel check from @sentry/nextjs to @sentry/node
- Use `console.warn` instead of `logger.warn` - Do not re-throw the error
1 parent c04cf80 commit 034fd7b

File tree

4 files changed

+38
-27
lines changed

4 files changed

+38
-27
lines changed

packages/nextjs/src/index.server.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,6 @@ 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-
}
9182
nodeInit(options);
9283

9384
const filterTransactions: EventProcessor = event => {

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,24 +139,6 @@ 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-
160142
describe('integrations', () => {
161143
// Options passed by `@sentry/nextjs`'s `init` to `@sentry/node`'s `init` after modifying them
162144
type ModifiedInitOptions = { integrations: Integration[] };

packages/node/src/sdk.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export const defaultIntegrations = [
107107
*
108108
* @see {@link NodeOptions} for documentation on configuration options.
109109
*/
110+
// eslint-disable-next-line complexity
110111
export function init(options: NodeOptions = {}): void {
111112
const carrier = getMainCarrier();
112113
const autoloadedIntegrations = carrier.__SENTRY__?.integrations || [];
@@ -157,6 +158,18 @@ export function init(options: NodeOptions = {}): void {
157158
setHubOnCarrier(carrier, getCurrentHub());
158159
}
159160

161+
if (options.tunnel !== undefined) {
162+
try {
163+
new URL(options.tunnel);
164+
} catch (error) {
165+
// eslint-disable-next-line no-console
166+
console.warn(
167+
'The tunnel option is not a valid URL. It must be a full URL including the protocol when using the Node transport.',
168+
);
169+
options.tunnel = undefined;
170+
}
171+
}
172+
160173
// TODO(v7): Refactor this to reduce the logic above
161174
const clientOptions: NodeClientOptions = {
162175
...options,

packages/node/test/sdk.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const defaultIntegrationsBackup = sdk.defaultIntegrations;
2020

2121
describe('init()', () => {
2222
beforeEach(() => {
23+
jest.clearAllMocks();
2324
global.__SENTRY__ = {};
2425
});
2526

@@ -89,4 +90,28 @@ describe('init()', () => {
8990
expect(mockDefaultIntegrations[1].setupOnce as jest.Mock).toHaveBeenCalledTimes(0);
9091
expect(newIntegration.setupOnce as jest.Mock).toHaveBeenCalledTimes(1);
9192
});
93+
94+
it('should not error on valid tunnel option', () => {
95+
const consoleWarnSpy = jest.spyOn(console, 'warn');
96+
expect(() =>
97+
init({
98+
dsn: 'https://[email protected]/12312012',
99+
tunnel: 'https://example.com/api',
100+
}),
101+
).not.toThrowError();
102+
expect(consoleWarnSpy).not.toHaveBeenCalledWith(
103+
'The tunnel option is not a valid URL. It must be a full URL including the protocol when using the Node transport.',
104+
);
105+
});
106+
107+
it('should not error on invalid tunnel option', () => {
108+
const consoleWarnSpy = jest.spyOn(console, 'warn');
109+
init({
110+
dsn: 'https://[email protected]/12312012',
111+
tunnel: '/invalid',
112+
});
113+
expect(consoleWarnSpy).toHaveBeenCalledWith(
114+
'The tunnel option is not a valid URL. It must be a full URL including the protocol when using the Node transport.',
115+
);
116+
});
92117
});

0 commit comments

Comments
 (0)