rollbar 2.23.0 → 2.25.0

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.
@@ -21,15 +21,31 @@ async function wait(ms) {
21
21
  });
22
22
  }
23
23
 
24
- async function throwInTypescriptFile(rollbar, callback) {
24
+ async function throwInScriptFile(rollbar, filepath, callback) {
25
25
  setTimeout(function () {
26
- var error = require('../examples/node-typescript/dist/index');
26
+ var error = require(filepath);
27
27
  error();
28
28
  }, 10);
29
29
  await wait(500);
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': {
@@ -256,8 +272,8 @@ vows.describe('transforms')
256
272
  }
257
273
  })
258
274
  .addBatch({
259
- 'handleItemWithError': {
260
- 'nodeSourceMaps': {
275
+ 'nodeSourceMaps': {
276
+ 'with original source present': {
261
277
  topic: function() {
262
278
  var Rollbar = new rollbar({
263
279
  accessToken: 'abc123',
@@ -267,9 +283,10 @@ vows.describe('transforms')
267
283
  var queue = Rollbar.client.notifier.queue;
268
284
  Rollbar.addItemStub = sinon.stub(queue, 'addItem');
269
285
 
270
- throwInTypescriptFile(Rollbar, this.callback);
286
+ throwInScriptFile(Rollbar, '../examples/node-typescript/dist/index',
287
+ this.callback);
271
288
  },
272
- 'should map the stack': function(r) {
289
+ 'should map the stack with context': function(r) {
273
290
  var addItem = r.addItemStub;
274
291
 
275
292
  assert.isTrue(addItem.called);
@@ -279,8 +296,15 @@ vows.describe('transforms')
279
296
  assert.equal(frame.lineno, 10);
280
297
  assert.equal(frame.colno, 22);
281
298
  assert.equal(frame.code, " var error = <Error> new CustomError('foo');");
299
+ assert.equal(frame.context.pre[0], ' }');
300
+ assert.equal(frame.context.pre[1], ' }');
301
+ assert.equal(frame.context.pre[2],
302
+ ' // TypeScript code snippet will include `<Error>`');
303
+ assert.equal(frame.context.post[0], ' throw error;');
304
+ assert.equal(frame.context.post[1], '}');
282
305
 
283
- var sourceMappingURLs = addItem.getCall(0).args[0].notifier.diagnostic.node_source_maps.source_mapping_urls;
306
+ var sourceMappingURLs = addItem.getCall(0).args[0].notifier.diagnostic
307
+ .node_source_maps.source_mapping_urls;
284
308
  var urls = Object.keys(sourceMappingURLs);
285
309
  assert.ok(urls[0].includes('index.js'));
286
310
  assert.ok(sourceMappingURLs[urls[0]].includes('index.js.map'));
@@ -295,8 +319,55 @@ vows.describe('transforms')
295
319
  assert.ok(sourceMappingURLs[urls[2]].includes('not found'));
296
320
  }
297
321
  addItem.reset();
322
+ }
323
+ }
324
+ }
325
+ })
326
+ .addBatch({
327
+ 'nodeSourceMaps': {
328
+ 'using sourcesContent': {
329
+ topic: function() {
330
+ var Rollbar = new rollbar({
331
+ accessToken: 'abc123',
332
+ captureUncaught: true,
333
+ nodeSourceMaps: true
334
+ });
335
+ var queue = Rollbar.client.notifier.queue;
336
+ Rollbar.addItemStub = sinon.stub(queue, 'addItem');
337
+
338
+ throwInScriptFile(Rollbar, '../examples/node-dist/index', this.callback);
298
339
  },
299
- },
340
+ 'should map the stack with context': function(r) {
341
+ var addItem = r.addItemStub;
342
+
343
+ assert.isTrue(addItem.called);
344
+ if (addItem.called) {
345
+ var frame = addItem.getCall(0).args[0].body.trace_chain[0].frames.pop();
346
+ assert.ok(frame.filename.includes('src/index.ts'));
347
+ assert.equal(frame.lineno, 10);
348
+ assert.equal(frame.colno, 22);
349
+ assert.equal(frame.code, " var error = <Error> new CustomError('foo');");
350
+ assert.equal(frame.context.pre[0], ' }');
351
+ assert.equal(frame.context.pre[1], ' }');
352
+ assert.equal(frame.context.pre[2],
353
+ ' // TypeScript code snippet will include `<Error>`');
354
+ assert.equal(frame.context.post[0], ' throw error;');
355
+ assert.equal(frame.context.post[1], '}');
356
+
357
+ var sourceMappingURLs = addItem.getCall(0).args[0].notifier.diagnostic
358
+ .node_source_maps.source_mapping_urls;
359
+ var urls = Object.keys(sourceMappingURLs);
360
+ assert.ok(urls.length === 1);
361
+ assert.ok(urls[0].includes('index.js'));
362
+ assert.ok(sourceMappingURLs[urls[0]].includes('index.js.map'));
363
+ }
364
+ addItem.reset();
365
+ }
366
+ }
367
+ }
368
+ })
369
+ .addBatch({
370
+ 'handleItemWithError': {
300
371
  'options': {
301
372
  'anything': {
302
373
  topic: function() {
@@ -439,7 +510,42 @@ vows.describe('transforms')
439
510
  assert.equal(item.data.custom.err1, 'nested context');
440
511
  assert.equal(item.data.custom.err2, 'error context');
441
512
  }
442
- }
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
+ },
443
549
  }
444
550
  }
445
551
  }