@@ -30,6 +30,10 @@ function itemFromArgs(args) {
30
30
return item ;
31
31
}
32
32
33
+ function chromeMajorVersion ( ) {
34
+ return parseInt ( navigator . userAgent . match ( / C h r o m e \/ ( [ 0 - 9 ] + ) \. / ) [ 1 ] ) ;
35
+ }
36
+
33
37
describe ( 'handleDomException' , function ( ) {
34
38
it ( 'should do nothing if not a DOMException' , function ( done ) {
35
39
var err = new Error ( 'test' ) ;
@@ -452,6 +456,45 @@ describe('addBody', function() {
452
456
} ) ;
453
457
} ) ;
454
458
} ) ;
459
+ describe ( 'with error cause' , function ( ) {
460
+ // Error cause was introduced in Chrome 93.
461
+ if ( chromeMajorVersion ( ) < 93 ) return ;
462
+
463
+ it ( 'should create trace_chain' , function ( done ) {
464
+ var causeErr = new Error ( 'cause error' ) ;
465
+ var err = new Error ( 'test error' , { cause : causeErr } ) ;
466
+ var args = [ 'a message' , err ] ;
467
+ var item = itemFromArgs ( args ) ;
468
+ var options = { } ;
469
+ t . handleItemWithError ( item , options , function ( e , i ) {
470
+ expect ( i . stackInfo ) . to . be . ok ( ) ;
471
+ } ) ;
472
+ t . addBody ( item , options , function ( e , i ) {
473
+ expect ( i . data . body . trace_chain . length ) . to . eql ( 2 ) ;
474
+ expect ( i . data . body . trace_chain [ 0 ] . exception . message ) . to . eql ( 'test error' ) ;
475
+ expect ( i . data . body . trace_chain [ 1 ] . exception . message ) . to . eql ( 'cause error' ) ;
476
+ done ( e ) ;
477
+ } ) ;
478
+ } ) ;
479
+ it ( 'should create add error context as custom data' , function ( done ) {
480
+ var causeErr = new Error ( 'cause error' ) ;
481
+ causeErr . rollbarContext = { err1 : 'cause context' } ;
482
+ var err = new Error ( 'test error' , { cause : causeErr } ) ;
483
+ err . rollbarContext = { err2 : 'error context' } ;
484
+ var args = [ 'a message' , err ] ;
485
+ var item = itemFromArgs ( args ) ;
486
+ var options = { addErrorContext : true } ;
487
+ t . handleItemWithError ( item , options , function ( e , i ) {
488
+ expect ( i . stackInfo ) . to . be . ok ( ) ;
489
+ } ) ;
490
+ t . addBody ( item , options , function ( e , i ) {
491
+ expect ( i . data . body . trace_chain . length ) . to . eql ( 2 ) ;
492
+ expect ( i . data . custom . err1 ) . to . eql ( 'cause context' ) ;
493
+ expect ( i . data . custom . err2 ) . to . eql ( 'error context' ) ;
494
+ done ( e ) ;
495
+ } ) ;
496
+ } ) ;
497
+ } ) ;
455
498
} ) ;
456
499
457
500
describe ( 'scrubPayload' , function ( ) {
0 commit comments