File tree Expand file tree Collapse file tree 2 files changed +47
-4
lines changed Expand file tree Collapse file tree 2 files changed +47
-4
lines changed Original file line number Diff line number Diff line change @@ -157,15 +157,31 @@ module.exports.patchGlobal = function patchGlobal(client, cb) {
157
157
// at the end, if we still don't have a Client, let's make one!
158
158
! ( client instanceof Client ) && ( client = new Client ( ) ) ;
159
159
160
+ var called = false ;
160
161
process . on ( 'uncaughtException' , function ( err ) {
161
162
if ( cb ) { // bind event listeners only if a callback was supplied
162
- client . once ( 'logged' , function ( ) {
163
+ var onLogged = function onLogged ( ) {
164
+ called = false ;
163
165
cb ( true , err ) ;
164
- } ) ;
165
- client . once ( 'error' , function ( ) {
166
+ } ;
167
+
168
+ var onError = function onError ( ) {
169
+ called = false ;
166
170
cb ( false , err ) ;
167
- } ) ;
171
+ } ;
172
+
173
+ if ( called ) {
174
+ client . removeListener ( 'logged' , onLogged ) ;
175
+ client . removeListener ( 'error' , onError ) ;
176
+ return cb ( false , err ) ;
177
+ }
178
+
179
+ client . once ( 'logged' , onLogged ) ;
180
+ client . once ( 'error' , onError ) ;
168
181
}
182
+
183
+ called = true ;
184
+
169
185
client . captureError ( err , function ( result ) {
170
186
node_util . log ( 'uncaughtException: ' + client . getIdent ( result ) ) ;
171
187
} ) ;
Original file line number Diff line number Diff line change @@ -295,6 +295,33 @@ describe('raven.Client', function(){
295
295
} ) ;
296
296
process . emit ( 'uncaughtException' , new Error ( 'derp' ) ) ;
297
297
} ) ;
298
+
299
+ it ( 'should not enter in recursion when an error is thrown on client request' , function ( done ) {
300
+ // remove existing uncaughtException handlers
301
+ var uncaughtBefore = process . _events . uncaughtException ;
302
+ process . removeAllListeners ( 'uncaughtException' ) ;
303
+
304
+ var transportBefore = client . transport . send ;
305
+
306
+ client . transport . send = function ( ) {
307
+ throw new Error ( 'foo' ) ;
308
+ } ;
309
+
310
+ client . patchGlobal ( function ( success , err ) {
311
+ success . should . eql ( false ) ;
312
+ err . should . be . instanceOf ( Error ) ;
313
+ err . message . should . equal ( 'foo' ) ;
314
+
315
+ // restore things to how they were
316
+ process . _events . uncaughtException = uncaughtBefore ;
317
+ client . transport . send = transportBefore ;
318
+
319
+ done ( ) ;
320
+ } ) ;
321
+
322
+
323
+ process . emit ( 'uncaughtException' , new Error ( 'derp' ) ) ;
324
+ } ) ;
298
325
} ) ;
299
326
300
327
it ( 'should use a custom transport' , function ( ) {
You can’t perform that action at this time.
0 commit comments