@@ -265,7 +265,9 @@ Raven.prototype = {
265
265
return func . apply ( this , args ) ;
266
266
} catch ( e ) {
267
267
self . _ignoreNextOnError ( ) ;
268
- self . captureException ( e , options , 1 ) ;
268
+ self . captureException ( e , objectMerge ( {
269
+ trimTailFrames : 1
270
+ } , options ) ) ;
269
271
throw e ;
270
272
}
271
273
}
@@ -310,11 +312,14 @@ Raven.prototype = {
310
312
* @param {object } options A specific set of options for this error [optional]
311
313
* @return {Raven }
312
314
*/
313
- captureException : function ( ex , options , skipframes ) {
314
- skipframes = skipframes || 0 ;
315
-
315
+ captureException : function ( ex , options ) {
316
316
// If not an Error is passed through, recall as a message instead
317
- if ( ! isError ( ex ) ) return this . captureMessage ( ex , options , skipframes + 1 ) ;
317
+ if ( ! isError ( ex ) ) {
318
+ return this . captureMessage ( ex , objectMerge ( {
319
+ trimHeadFrames : 1 ,
320
+ stacktrace : true // if we fall back to captureMessage, default to attempting a new trace
321
+ } , options ) ) ;
322
+ }
318
323
319
324
// Store the raw exception object for potential debugging and introspection
320
325
this . _lastCapturedException = ex ;
@@ -326,7 +331,7 @@ Raven.prototype = {
326
331
// report on.
327
332
try {
328
333
var stack = TraceKit . computeStackTrace ( ex ) ;
329
- this . _handleStackInfo ( stack , options , skipframes ) ;
334
+ this . _handleStackInfo ( stack , options ) ;
330
335
} catch ( ex1 ) {
331
336
if ( ex !== ex1 ) {
332
337
throw ex1 ;
@@ -343,7 +348,36 @@ Raven.prototype = {
343
348
* @param {object } options A specific set of options for this message [optional]
344
349
* @return {Raven }
345
350
*/
346
- captureMessage : function ( msg , options , skipframes ) {
351
+ captureMessage : function ( msg , options ) {
352
+ if ( options . stacktrace ) {
353
+ var ex ;
354
+ // create a stack trace from this point; just trim
355
+ // off extra frames so they don't include this function call (or
356
+ // earlier Raven.js library fn calls)
357
+ try {
358
+ throw new Error ( msg ) ;
359
+ } catch ( ex1 ) {
360
+ ex = ex1 ;
361
+ }
362
+
363
+ // null exception name so `Error` isn't prefixed to msg
364
+ ex . name = null ;
365
+
366
+ options = objectMerge ( {
367
+ // fingerprint on msg, not stack trace
368
+ // NOTE: need also to do this because stack could include Raven.wrap,
369
+ // which may create inconsistent traces if only using window.onerror
370
+ fingerprint : msg ,
371
+ trimTailFrames : ( options . trimHeadFrames || 0 ) + 1
372
+ } , options ) ;
373
+
374
+ // infinite loop if ex *somehow* returns false for isError
375
+ // is that possible when it is result of try/catch?
376
+ this . captureException ( ex , options ) ;
377
+
378
+ return this ;
379
+ }
380
+
347
381
// config() automagically converts ignoreErrors from a list to a RegExp so we need to test for an
348
382
// early call; we'll error on the side of logging anything called before configuration since it's
349
383
// probably something you should see:
@@ -1007,7 +1041,7 @@ Raven.prototype = {
1007
1041
}
1008
1042
} ,
1009
1043
1010
- _handleStackInfo : function ( stackInfo , options , skipframes ) {
1044
+ _handleStackInfo : function ( stackInfo , options ) {
1011
1045
var self = this ;
1012
1046
var frames = [ ] ;
1013
1047
@@ -1019,8 +1053,13 @@ Raven.prototype = {
1019
1053
}
1020
1054
} ) ;
1021
1055
1022
- if ( skipframes ) {
1023
- frames = frames . slice ( 0 , skipframes ) ;
1056
+ // e.g. frames captured via captureMessage throw
1057
+ if ( options . trimHeadFrames ) {
1058
+ frames = frames . slice ( options . trimHeadFrames ) ;
1059
+ }
1060
+ // e.g. try/catch (wrapper) frames
1061
+ if ( options . trimTailFrames ) {
1062
+ frames = frames . slice ( 0 , options . trimTailFrames ) ;
1024
1063
}
1025
1064
}
1026
1065
0 commit comments