File tree Expand file tree Collapse file tree 4 files changed +38
-27
lines changed Expand file tree Collapse file tree 4 files changed +38
-27
lines changed Original file line number Diff line number Diff line change @@ -79,15 +79,6 @@ export function init(options: NextjsOptions): void {
79
79
const activeDomain = domain . active ;
80
80
domain . active = null ;
81
81
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
- }
91
82
nodeInit ( options ) ;
92
83
93
84
const filterTransactions : EventProcessor = event => {
Original file line number Diff line number Diff line change @@ -139,24 +139,6 @@ describe('Server init()', () => {
139
139
} ) ;
140
140
} ) ;
141
141
142
- it ( 'should not fail on valid tunnel option' , ( ) => {
143
- expect ( ( ) =>
144
- init ( {
145
- dsn : 'https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/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://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/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
-
160
142
describe ( 'integrations' , ( ) => {
161
143
// Options passed by `@sentry/nextjs`'s `init` to `@sentry/node`'s `init` after modifying them
162
144
type ModifiedInitOptions = { integrations : Integration [ ] } ;
Original file line number Diff line number Diff line change @@ -107,6 +107,7 @@ export const defaultIntegrations = [
107
107
*
108
108
* @see {@link NodeOptions } for documentation on configuration options.
109
109
*/
110
+ // eslint-disable-next-line complexity
110
111
export function init ( options : NodeOptions = { } ) : void {
111
112
const carrier = getMainCarrier ( ) ;
112
113
const autoloadedIntegrations = carrier . __SENTRY__ ?. integrations || [ ] ;
@@ -157,6 +158,18 @@ export function init(options: NodeOptions = {}): void {
157
158
setHubOnCarrier ( carrier , getCurrentHub ( ) ) ;
158
159
}
159
160
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
+
160
173
// TODO(v7): Refactor this to reduce the logic above
161
174
const clientOptions : NodeClientOptions = {
162
175
...options ,
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ const defaultIntegrationsBackup = sdk.defaultIntegrations;
20
20
21
21
describe ( 'init()' , ( ) => {
22
22
beforeEach ( ( ) => {
23
+ jest . clearAllMocks ( ) ;
23
24
global . __SENTRY__ = { } ;
24
25
} ) ;
25
26
@@ -89,4 +90,28 @@ describe('init()', () => {
89
90
expect ( mockDefaultIntegrations [ 1 ] . setupOnce as jest . Mock ) . toHaveBeenCalledTimes ( 0 ) ;
90
91
expect ( newIntegration . setupOnce as jest . Mock ) . toHaveBeenCalledTimes ( 1 ) ;
91
92
} ) ;
93
+
94
+ it ( 'should not error on valid tunnel option' , ( ) => {
95
+ const consoleWarnSpy = jest . spyOn ( console , 'warn' ) ;
96
+ expect ( ( ) =>
97
+ init ( {
98
+ dsn : 'https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/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://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/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
+ } ) ;
92
117
} ) ;
You can’t perform that action at this time.
0 commit comments