@@ -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,35 @@ 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 remove
355
+ // off extra frames so they don't include Raven.js code
356
+ try {
357
+ throw new Error ( msg ) ;
358
+ } catch ( ex1 ) {
359
+ ex = ex1 ;
360
+ this . _lastCapturedException = ex ;
361
+ }
362
+
363
+ ex . name = null ;
364
+
365
+ options = objectMerge ( {
366
+ // fingerprint on msg, not stack trace
367
+ // NOTE: need also to do this because stack could include Raven.wrap,
368
+ // which may create inconsistent traces if only using window.onerror
369
+ fingerprint : msg ,
370
+ trimTailFrames : ( options . trimHeadFrames || 0 ) + 1
371
+ } , options ) ;
372
+
373
+ // infinite loop if ex *somehow* returns false for isError
374
+ // is that possible when it is result of try/catch?
375
+ this . captureException ( ex , options ) ;
376
+
377
+ return this ;
378
+ }
379
+
347
380
// config() automagically converts ignoreErrors from a list to a RegExp so we need to test for an
348
381
// early call; we'll error on the side of logging anything called before configuration since it's
349
382
// probably something you should see:
@@ -1007,7 +1040,7 @@ Raven.prototype = {
1007
1040
}
1008
1041
} ,
1009
1042
1010
- _handleStackInfo : function ( stackInfo , options , skipframes ) {
1043
+ _handleStackInfo : function ( stackInfo , options ) {
1011
1044
var self = this ;
1012
1045
var frames = [ ] ;
1013
1046
@@ -1019,8 +1052,13 @@ Raven.prototype = {
1019
1052
}
1020
1053
} ) ;
1021
1054
1022
- if ( skipframes ) {
1023
- frames = frames . slice ( 0 , skipframes ) ;
1055
+ // e.g. frames captured via captureMessage throw
1056
+ if ( options . trimHeadFrames ) {
1057
+ frames = frames . slice ( options . trimHeadFrames ) ;
1058
+ }
1059
+ // e.g. try/catch (wrapper) frames
1060
+ if ( options . trimTailFrames ) {
1061
+ frames = frames . slice ( 0 , options . trimTailFrames ) ;
1024
1062
}
1025
1063
}
1026
1064
0 commit comments