rollbar 2.24.0 → 2.24.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.
package/index.d.ts CHANGED
@@ -89,7 +89,7 @@ declare namespace Rollbar {
89
89
  stackTraceLimit?: number;
90
90
  telemetryScrubber?: TelemetryScrubber;
91
91
  timeout?: number;
92
- transform?: (data: object) => void;
92
+ transform?: (data: object, item: object) => void;
93
93
  transmit?: boolean;
94
94
  uncaughtErrorLevel?: Level;
95
95
  verbose?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollbar",
3
- "version": "2.24.0",
3
+ "version": "2.24.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "http://github.com/rollbar/rollbar.js"
@@ -66,7 +66,6 @@
66
66
  "karma-sourcemap-loader": "^0.3.5",
67
67
  "karma-webpack": "^4.0.2",
68
68
  "mocha": "^7.1.2",
69
- "mootools": "^1.5.1",
70
69
  "natives": "^1.1.6",
71
70
  "nock": "^11.9.1",
72
71
  "node-libs-browser": "^0.5.2",
@@ -78,7 +77,7 @@
78
77
  "strict-loader": "^1.2.0",
79
78
  "time-grunt": "^1.0.0",
80
79
  "vows": "^0.8.3",
81
- "webpack": "^4.41.5"
80
+ "webpack": "^4.46.0"
82
81
  },
83
82
  "optionalDependencies": {
84
83
  "decache": "^3.0.5"
package/src/defaults.js CHANGED
@@ -1,5 +1,5 @@
1
1
  module.exports = {
2
- version: '2.24.0',
2
+ version: '2.24.1',
3
3
  endpoint: 'api.rollbar.com/api/1/item/',
4
4
  logLevel: 'debug',
5
5
  reportLevel: 'debug',
package/src/utility.js CHANGED
@@ -398,6 +398,37 @@ function wrapCallback(logger, f) {
398
398
  };
399
399
  }
400
400
 
401
+ function nonCircularClone(obj) {
402
+ var seen = [obj];
403
+
404
+ function clone(obj, seen) {
405
+ var value, name, newSeen, result = {};
406
+
407
+ try {
408
+ for (name in obj) {
409
+ value = obj[name];
410
+
411
+ if (value && (isType(value, 'object') || isType(value, 'array'))) {
412
+ if (seen.includes(value)) {
413
+ result[name] = 'Removed circular reference: ' + typeName(value);
414
+ } else {
415
+ newSeen = seen.slice();
416
+ newSeen.push(value);
417
+ result[name] = clone(value, newSeen);
418
+ }
419
+ continue;
420
+ }
421
+
422
+ result[name] = value;
423
+ }
424
+ } catch (e) {
425
+ result = 'Failed cloning custom data: ' + e.message;
426
+ }
427
+ return result;
428
+ }
429
+ return clone(obj, seen);
430
+ }
431
+
401
432
  function createItem(args, logger, notifier, requestKeys, lambdaContext) {
402
433
  var message, err, custom, callback, request;
403
434
  var arg;
@@ -455,10 +486,12 @@ function createItem(args, logger, notifier, requestKeys, lambdaContext) {
455
486
  }
456
487
  }
457
488
 
489
+ // if custom is an array this turns it into an object with integer keys
490
+ if (custom) custom = nonCircularClone(custom);
491
+
458
492
  if (extraArgs.length > 0) {
459
- // if custom is an array this turns it into an object with integer keys
460
- custom = merge(custom);
461
- custom.extraArgs = extraArgs;
493
+ if (!custom) custom = nonCircularClone({});
494
+ custom.extraArgs = nonCircularClone(extraArgs);
462
495
  }
463
496
 
464
497
  var item = {
@@ -503,7 +536,7 @@ function addErrorContext(item, errors) {
503
536
  try {
504
537
  for (var i = 0; i < errors.length; ++i) {
505
538
  if (errors[i].hasOwnProperty('rollbarContext')) {
506
- custom = merge(custom, errors[i].rollbarContext);
539
+ custom = merge(custom, nonCircularClone(errors[i].rollbarContext));
507
540
  contextAdded = true;
508
541
  }
509
542
  }
@@ -503,6 +503,58 @@ describe('log', function() {
503
503
  done();
504
504
  })
505
505
 
506
+ it('should remove circular references in custom data', function(done) {
507
+ var server = window.server;
508
+ stubResponse(server);
509
+ server.requests.length = 0;
510
+
511
+ var options = {
512
+ accessToken: 'POST_CLIENT_ITEM_TOKEN',
513
+ addErrorContext: true
514
+ };
515
+ var rollbar = window.rollbar = new Rollbar(options);
516
+
517
+ var err = new Error('test error');
518
+ var contextData = { extra: 'baz' }
519
+ contextData.data = contextData;
520
+ var context = { err: 'test', contextData: contextData };
521
+ err.rollbarContext = context;
522
+
523
+ var array = ['one', 'two'];
524
+ array.push(array);
525
+ var custom = { foo: 'bar', array: array };
526
+ var notCircular = { key: 'value' };
527
+ custom.notCircular1 = notCircular;
528
+ custom.notCircular2 = notCircular;
529
+ custom.self = custom;
530
+ rollbar.error(err, custom);
531
+
532
+ server.respond();
533
+
534
+ var body = JSON.parse(server.requests[0].requestBody);
535
+
536
+ expect(body.data.body.trace.exception.message).to.eql('test error');
537
+ expect(body.data.custom.foo).to.eql('bar');
538
+ expect(body.data.custom.err).to.eql('test');
539
+
540
+ // Duplicate objects are allowed when there is no circular reference.
541
+ expect(body.data.custom.notCircular1).to.eql(notCircular);
542
+ expect(body.data.custom.notCircular2).to.eql(notCircular);
543
+
544
+ expect(body.data.custom.self).to.eql(
545
+ 'Removed circular reference: object'
546
+ );
547
+ expect(body.data.custom.array).to.eql([
548
+ 'one', 'two', 'Removed circular reference: array'
549
+ ]);
550
+ expect(body.data.custom.contextData).to.eql({
551
+ extra: 'baz',
552
+ data: 'Removed circular reference: object'
553
+ });
554
+
555
+ done();
556
+ })
557
+
506
558
  it('should send message when called with only null arguments', function(done) {
507
559
  var server = window.server;
508
560
  stubResponse(server);
@@ -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
  }