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