rollbar 2.24.0 → 2.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,6 +30,10 @@ function itemFromArgs(args) {
30
30
  return item;
31
31
  }
32
32
 
33
+ function chromeMajorVersion() {
34
+ return parseInt(navigator.userAgent.match(/Chrome\/([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() {
@@ -422,11 +422,13 @@ describe('callback options', function() {
422
422
 
423
423
  rollbar.log('test'); // generate a payload to inspect
424
424
 
425
- expect(window.fetchStub.called).to.be.ok();
426
- var body = JSON.parse(window.fetchStub.getCall(0).args[1].body);
427
- expect(body.data.foo).to.eql('bar');
425
+ setTimeout(function() {
426
+ expect(window.fetchStub.called).to.be.ok();
427
+ var body = JSON.parse(window.fetchStub.getCall(0).args[1].body);
428
+ expect(body.data.foo).to.eql('bar');
428
429
 
429
- done();
430
+ done();
431
+ }, 1);
430
432
  });
431
433
 
432
434
  it('should use transform when set', function(done) {
@@ -442,11 +444,13 @@ describe('callback options', function() {
442
444
 
443
445
  rollbar.log('test'); // generate a payload to inspect
444
446
 
445
- expect(window.fetchStub.called).to.be.ok();
446
- var body = JSON.parse(window.fetchStub.getCall(0).args[1].body);
447
- expect(body.data.foo).to.eql('baz');
447
+ setTimeout(function() {
448
+ expect(window.fetchStub.called).to.be.ok();
449
+ var body = JSON.parse(window.fetchStub.getCall(0).args[1].body);
450
+ expect(body.data.foo).to.eql('baz');
448
451
 
449
- done();
452
+ done();
453
+ }, 1);
450
454
  });
451
455
  });
452
456
 
@@ -278,7 +278,7 @@ vows.describe('rollbar')
278
278
  var item = r.client.logCalls[r.client.logCalls.length - 1].item;
279
279
  assert.equal(item.message, message);
280
280
  assert.equal(item.request, request);
281
- assert.equal(item.custom, custom);
281
+ assert.deepStrictEqual(item.custom, custom);
282
282
  item.callback();
283
283
  assert.isTrue(callbackCalled);
284
284
  }
@@ -332,7 +332,7 @@ vows.describe('rollbar')
332
332
  var item = r.client.logCalls[r.client.logCalls.length - 1].item
333
333
  assert.equal(item.message, message)
334
334
  assert.equal(item.request, request)
335
- assert.equal(item.custom, custom)
335
+ assert.deepStrictEqual(item.custom, custom)
336
336
  },
337
337
  'should work with request and custom and callback': function(r) {
338
338
  var message = 'hello'
@@ -346,7 +346,7 @@ vows.describe('rollbar')
346
346
  var item = r.client.logCalls[r.client.logCalls.length - 1].item
347
347
  assert.equal(item.message, message)
348
348
  assert.equal(item.request, request)
349
- assert.equal(item.custom, custom)
349
+ assert.deepStrictEqual(item.custom, custom)
350
350
  item.callback();
351
351
  assert.isTrue(callbackCalled);
352
352
  }
@@ -399,7 +399,7 @@ vows.describe('rollbar')
399
399
  var item = r.client.logCalls[r.client.logCalls.length - 1].item
400
400
  assert.equal(item.err, err)
401
401
  assert.equal(item.request, request)
402
- assert.equal(item.custom, custom)
402
+ assert.deepStrictEqual(item.custom, custom)
403
403
  item.callback();
404
404
  assert.isTrue(callbackCalled);
405
405
  }
@@ -453,7 +453,7 @@ vows.describe('rollbar')
453
453
  var item = r.client.logCalls[r.client.logCalls.length - 1].item
454
454
  assert.equal(item.err, err)
455
455
  assert.equal(item.request, request)
456
- assert.equal(item.custom, custom)
456
+ assert.deepStrictEqual(item.custom, custom)
457
457
  },
458
458
  'should work with request and custom and callback': function(r) {
459
459
  var err = new Error('hello!')
@@ -467,7 +467,7 @@ vows.describe('rollbar')
467
467
  var item = r.client.logCalls[r.client.logCalls.length - 1].item
468
468
  assert.equal(item.err, err)
469
469
  assert.equal(item.request, request)
470
- assert.equal(item.custom, custom)
470
+ assert.deepStrictEqual(item.custom, custom)
471
471
  item.callback();
472
472
  assert.isTrue(callbackCalled);
473
473
  }
@@ -30,6 +30,22 @@ async function throwInScriptFile(rollbar, filepath, callback) {
30
30
  callback(rollbar);
31
31
  }
32
32
 
33
+ var nodeVersion = function () {
34
+ var version = process.versions.node.split('.');
35
+
36
+ return [
37
+ parseInt(version[0]),
38
+ parseInt(version[1]),
39
+ parseInt(version[2]),
40
+ ];
41
+ }();
42
+
43
+ var isMinNodeVersion = function(major, minor) {
44
+ return (
45
+ nodeVersion[0] > major || (nodeVersion[0] === major && nodeVersion[1] >= minor)
46
+ );
47
+ }
48
+
33
49
  vows.describe('transforms')
34
50
  .addBatch({
35
51
  'baseData': {
@@ -494,7 +510,42 @@ vows.describe('transforms')
494
510
  assert.equal(item.data.custom.err1, 'nested context');
495
511
  assert.equal(item.data.custom.err2, 'error context');
496
512
  }
497
- }
513
+ },
514
+ 'with an error cause': {
515
+ topic: function (options) {
516
+ var test = function() {
517
+ var x = thisVariableIsNotDefined;
518
+ };
519
+ var err;
520
+ try {
521
+ test();
522
+ } catch (e) {
523
+ err = new Error('cause message', { cause: e });
524
+ e.rollbarContext = { err1: 'cause context' };
525
+ err.rollbarContext = { err2: 'error context' };
526
+ }
527
+ var item = {
528
+ data: {body: {}},
529
+ err: err
530
+ };
531
+ t.handleItemWithError(item, options, this.callback);
532
+ },
533
+ 'should not error': function(err, item) {
534
+ assert.ifError(err);
535
+ },
536
+ 'should have the right data in the trace_chain': function(err, item) {
537
+ // Error cause was introduced in Node 16.9.
538
+ if (!isMinNodeVersion(16, 9)) return;
539
+
540
+ var trace_chain = item.stackInfo;
541
+ assert.lengthOf(trace_chain, 2);
542
+ assert.equal(trace_chain[0].exception.class, 'Error');
543
+ assert.equal(trace_chain[0].exception.message, 'cause message');
544
+ assert.equal(trace_chain[1].exception.class, 'ReferenceError');
545
+ assert.equal(item.data.custom.err1, 'cause context');
546
+ assert.equal(item.data.custom.err2, 'error context');
547
+ }
548
+ },
498
549
  }
499
550
  }
500
551
  }