@@ -278,7 +278,9 @@ Raven.prototype = {
278
278
return func . apply ( this , args ) ;
279
279
} catch ( e ) {
280
280
self . _ignoreNextOnError ( ) ;
281
- self . captureException ( e , options , 1 ) ;
281
+ self . captureException ( e , objectMerge ( {
282
+ trimTailFrames : 1
283
+ } , options ) ) ;
282
284
throw e ;
283
285
}
284
286
}
@@ -323,11 +325,14 @@ Raven.prototype = {
323
325
* @param {object } options A specific set of options for this error [optional]
324
326
* @return {Raven }
325
327
*/
326
- captureException : function ( ex , options , skipframes ) {
327
- skipframes = skipframes || 0 ;
328
-
328
+ captureException : function ( ex , options ) {
329
329
// If not an Error is passed through, recall as a message instead
330
- if ( ! isError ( ex ) ) return this . captureMessage ( ex , options , skipframes + 1 ) ;
330
+ if ( ! isError ( ex ) ) {
331
+ return this . captureMessage ( ex , objectMerge ( {
332
+ trimHeadFrames : 1 ,
333
+ stacktrace : true // if we fall back to captureMessage, default to attempting a new trace
334
+ } , options ) ) ;
335
+ }
331
336
332
337
// Store the raw exception object for potential debugging and introspection
333
338
this . _lastCapturedException = ex ;
@@ -339,7 +344,7 @@ Raven.prototype = {
339
344
// report on.
340
345
try {
341
346
var stack = TraceKit . computeStackTrace ( ex ) ;
342
- this . _handleStackInfo ( stack , options , skipframes ) ;
347
+ this . _handleStackInfo ( stack , options ) ;
343
348
} catch ( ex1 ) {
344
349
if ( ex !== ex1 ) {
345
350
throw ex1 ;
@@ -356,7 +361,36 @@ Raven.prototype = {
356
361
* @param {object } options A specific set of options for this message [optional]
357
362
* @return {Raven }
358
363
*/
359
- captureMessage : function ( msg , options , skipframes ) {
364
+ captureMessage : function ( msg , options ) {
365
+ if ( options . stacktrace ) {
366
+ var ex ;
367
+ // create a stack trace from this point; just trim
368
+ // off extra frames so they don't include this function call (or
369
+ // earlier Raven.js library fn calls)
370
+ try {
371
+ throw new Error ( msg ) ;
372
+ } catch ( ex1 ) {
373
+ ex = ex1 ;
374
+ }
375
+
376
+ // null exception name so `Error` isn't prefixed to msg
377
+ ex . name = null ;
378
+
379
+ options = objectMerge ( {
380
+ // fingerprint on msg, not stack trace
381
+ // NOTE: need also to do this because stack could include Raven.wrap,
382
+ // which may create inconsistent traces if only using window.onerror
383
+ fingerprint : msg ,
384
+ trimTailFrames : ( options . trimHeadFrames || 0 ) + 1
385
+ } , options ) ;
386
+
387
+ // infinite loop if ex *somehow* returns false for isError
388
+ // is that possible when it is result of try/catch?
389
+ this . captureException ( ex , options ) ;
390
+
391
+ return this ;
392
+ }
393
+
360
394
// config() automagically converts ignoreErrors from a list to a RegExp so we need to test for an
361
395
// early call; we'll error on the side of logging anything called before configuration since it's
362
396
// probably something you should see:
@@ -1066,7 +1100,7 @@ Raven.prototype = {
1066
1100
}
1067
1101
} ,
1068
1102
1069
- _handleStackInfo : function ( stackInfo , options , skipframes ) {
1103
+ _handleStackInfo : function ( stackInfo , options ) {
1070
1104
var self = this ;
1071
1105
var frames = [ ] ;
1072
1106
@@ -1078,8 +1112,13 @@ Raven.prototype = {
1078
1112
}
1079
1113
} ) ;
1080
1114
1081
- if ( skipframes ) {
1082
- frames = frames . slice ( 0 , skipframes ) ;
1115
+ // e.g. frames captured via captureMessage throw
1116
+ if ( options . trimHeadFrames ) {
1117
+ frames = frames . slice ( options . trimHeadFrames ) ;
1118
+ }
1119
+ // e.g. try/catch (wrapper) frames
1120
+ if ( options . trimTailFrames ) {
1121
+ frames = frames . slice ( 0 , options . trimTailFrames ) ;
1083
1122
}
1084
1123
}
1085
1124
0 commit comments