@honeybadger-io/js 4.6.2 → 4.7.4

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.
@@ -703,7 +703,7 @@ var store = {};
703
703
 
704
704
  Object.defineProperty(store, "__esModule", { value: true });
705
705
  store.GlobalStore = void 0;
706
- var util_1$4 = util$1;
706
+ var util_1$5 = util$1;
707
707
  var GlobalStore = /** @class */ (function () {
708
708
  function GlobalStore(contents, breadcrumbsLimit) {
709
709
  this.contents = contents;
@@ -720,7 +720,7 @@ var GlobalStore = /** @class */ (function () {
720
720
  return JSON.parse(JSON.stringify(value));
721
721
  };
722
722
  GlobalStore.prototype.setContext = function (context) {
723
- this.contents.context = (0, util_1$4.merge)(this.contents.context, context || {});
723
+ this.contents.context = (0, util_1$5.merge)(this.contents.context, context || {});
724
724
  };
725
725
  GlobalStore.prototype.addBreadcrumb = function (breadcrumb) {
726
726
  if (this.contents.breadcrumbs.length == this.breadcrumbsLimit) {
@@ -752,12 +752,12 @@ var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
752
752
  };
753
753
  Object.defineProperty(client, "__esModule", { value: true });
754
754
  client.Client = void 0;
755
- var util_1$3 = util$1;
755
+ var util_1$4 = util$1;
756
756
  var store_1 = store;
757
757
  var notifier = {
758
758
  name: 'honeybadger-js',
759
759
  url: 'https://github.com/honeybadger-io/honeybadger-js',
760
- version: '4.6.2'
760
+ version: '4.7.4'
761
761
  };
762
762
  // Split at commas and spaces
763
763
  var TAG_SEPARATOR = /,|\s+/;
@@ -773,7 +773,7 @@ var Client = /** @class */ (function () {
773
773
  this.config = __assign({ apiKey: null, endpoint: 'https://api.honeybadger.io', environment: null, hostname: null, projectRoot: null, component: null, action: null, revision: null, reportData: null, breadcrumbsEnabled: true, maxBreadcrumbs: 40, maxObjectDepth: 8, logger: console, developmentEnvironments: ['dev', 'development', 'test'], debug: false, tags: null, enableUncaught: true, enableUnhandledRejection: true, afterUncaught: function () { return true; }, filters: ['creditcard', 'password'], __plugins: [] }, opts);
774
774
  this.__initStore();
775
775
  this.__transport = transport;
776
- this.logger = (0, util_1$3.logger)(this);
776
+ this.logger = (0, util_1$4.logger)(this);
777
777
  }
778
778
  Client.prototype.getVersion = function () {
779
779
  return notifier.version;
@@ -843,14 +843,14 @@ var Client = /** @class */ (function () {
843
843
  }
844
844
  // we need to have the source file data before the beforeNotifyHandlers,
845
845
  // in case they modify them
846
- var sourceCodeData = notice && notice.backtrace ? notice.backtrace.map(function (trace) { return (0, util_1$3.shallowClone)(trace); }) : null;
847
- var beforeNotifyResult = (0, util_1$3.runBeforeNotifyHandlers)(notice, this.__beforeNotifyHandlers);
846
+ var sourceCodeData = notice && notice.backtrace ? notice.backtrace.map(function (trace) { return (0, util_1$4.shallowClone)(trace); }) : null;
847
+ var beforeNotifyResult = (0, util_1$4.runBeforeNotifyHandlers)(notice, this.__beforeNotifyHandlers);
848
848
  if (!preConditionError && !beforeNotifyResult) {
849
849
  this.logger.debug('skipping error report: beforeNotify handlers returned false', notice);
850
850
  preConditionError = new Error('beforeNotify handlers returned false');
851
851
  }
852
852
  if (preConditionError) {
853
- (0, util_1$3.runAfterNotifyHandlers)(notice, this.__afterNotifyHandlers, preConditionError);
853
+ (0, util_1$4.runAfterNotifyHandlers)(notice, this.__afterNotifyHandlers, preConditionError);
854
854
  return false;
855
855
  }
856
856
  this.addBreadcrumb('Honeybadger Notice', {
@@ -863,7 +863,7 @@ var Client = /** @class */ (function () {
863
863
  });
864
864
  var breadcrumbs = this.__store.getContents('breadcrumbs');
865
865
  notice.__breadcrumbs = this.config.breadcrumbsEnabled ? breadcrumbs : [];
866
- (0, util_1$3.getSourceForBacktrace)(sourceCodeData, this.__getSourceFileHandler)
866
+ (0, util_1$4.getSourceForBacktrace)(sourceCodeData, this.__getSourceFileHandler)
867
867
  .then(function (sourcePerTrace) {
868
868
  sourcePerTrace.forEach(function (source, index) {
869
869
  notice.backtrace[index].source = source;
@@ -877,26 +877,26 @@ var Client = /** @class */ (function () {
877
877
  'Accept': 'text/json, application/json'
878
878
  },
879
879
  method: 'POST',
880
- endpoint: (0, util_1$3.endpoint)(_this.config.endpoint, '/v1/notices/js'),
880
+ endpoint: (0, util_1$4.endpoint)(_this.config.endpoint, '/v1/notices/js'),
881
881
  maxObjectDepth: _this.config.maxObjectDepth,
882
882
  logger: _this.logger,
883
- async: (0, util_1$3.isBrowserConfig)(_this.config) ? _this.config.async : undefined,
883
+ async: (0, util_1$4.isBrowserConfig)(_this.config) ? _this.config.async : undefined,
884
884
  }, payload)
885
885
  .then(function (res) {
886
886
  if (res.statusCode !== 201) {
887
- (0, util_1$3.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, new Error("Bad HTTP response: ".concat(res.statusCode)));
887
+ (0, util_1$4.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, new Error("Bad HTTP response: ".concat(res.statusCode)));
888
888
  _this.logger.warn("Error report failed: unknown response from server. code=".concat(res.statusCode));
889
889
  return;
890
890
  }
891
891
  var uuid = JSON.parse(res.body).id;
892
- (0, util_1$3.runAfterNotifyHandlers)((0, util_1$3.merge)(notice, {
892
+ (0, util_1$4.runAfterNotifyHandlers)((0, util_1$4.merge)(notice, {
893
893
  id: uuid
894
894
  }), _this.__afterNotifyHandlers);
895
895
  _this.logger.info("Error report sent \u26A1 https://app.honeybadger.io/notice/".concat(uuid));
896
896
  })
897
897
  .catch(function (err) {
898
898
  _this.logger.error('Error report failed: an unknown error occurred.', "message=".concat(err.message));
899
- (0, util_1$3.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, err);
899
+ (0, util_1$4.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, err);
900
900
  });
901
901
  });
902
902
  return true;
@@ -949,18 +949,18 @@ var Client = /** @class */ (function () {
949
949
  Client.prototype.makeNotice = function (noticeable, name, extra) {
950
950
  if (name === void 0) { name = undefined; }
951
951
  if (extra === void 0) { extra = undefined; }
952
- var notice = (0, util_1$3.makeNotice)(noticeable);
952
+ var notice = (0, util_1$4.makeNotice)(noticeable);
953
953
  if (name && !(typeof name === 'object')) {
954
954
  var n = String(name);
955
955
  name = { name: n };
956
956
  }
957
957
  if (name) {
958
- notice = (0, util_1$3.mergeNotice)(notice, name);
958
+ notice = (0, util_1$4.mergeNotice)(notice, name);
959
959
  }
960
960
  if (typeof extra === 'object' && extra !== null) {
961
- notice = (0, util_1$3.mergeNotice)(notice, extra);
961
+ notice = (0, util_1$4.mergeNotice)(notice, extra);
962
962
  }
963
- if ((0, util_1$3.objectIsEmpty)(notice)) {
963
+ if ((0, util_1$4.objectIsEmpty)(notice)) {
964
964
  return null;
965
965
  }
966
966
  var context = this.__store.getContents('context');
@@ -970,9 +970,9 @@ var Client = /** @class */ (function () {
970
970
  // Turning into a Set will remove duplicates
971
971
  var tags = noticeTags.concat(contextTags).concat(configTags);
972
972
  var uniqueTags = tags.filter(function (item, index) { return tags.indexOf(item) === index; });
973
- notice = (0, util_1$3.merge)(notice, {
973
+ notice = (0, util_1$4.merge)(notice, {
974
974
  name: notice.name || 'Error',
975
- context: (0, util_1$3.merge)(context, notice.context),
975
+ context: (0, util_1$4.merge)(context, notice.context),
976
976
  projectRoot: notice.projectRoot || this.config.projectRoot,
977
977
  environment: notice.environment || this.config.environment,
978
978
  component: notice.component || this.config.component,
@@ -982,10 +982,10 @@ var Client = /** @class */ (function () {
982
982
  });
983
983
  var backtraceShift = 0;
984
984
  if (typeof notice.stack !== 'string' || !notice.stack.trim()) {
985
- notice.stack = (0, util_1$3.generateStackTrace)();
985
+ notice.stack = (0, util_1$4.generateStackTrace)();
986
986
  backtraceShift = 2;
987
987
  }
988
- notice.backtrace = (0, util_1$3.makeBacktrace)(notice.stack, backtraceShift);
988
+ notice.backtrace = (0, util_1$4.makeBacktrace)(notice.stack, backtraceShift);
989
989
  return notice;
990
990
  };
991
991
  Client.prototype.addBreadcrumb = function (message, opts) {
@@ -993,7 +993,7 @@ var Client = /** @class */ (function () {
993
993
  return;
994
994
  }
995
995
  opts = opts || {};
996
- var metadata = (0, util_1$3.shallowClone)(opts.metadata);
996
+ var metadata = (0, util_1$4.shallowClone)(opts.metadata);
997
997
  var category = opts.category || 'custom';
998
998
  var timestamp = new Date().toISOString();
999
999
  this.__store.addBreadcrumb({
@@ -1017,8 +1017,8 @@ var Client = /** @class */ (function () {
1017
1017
  return (this.config.environment && this.config.developmentEnvironments.includes(this.config.environment));
1018
1018
  };
1019
1019
  Client.prototype.__buildPayload = function (notice) {
1020
- var headers = (0, util_1$3.filter)(notice.headers, this.config.filters) || {};
1021
- var cgiData = (0, util_1$3.filter)(__assign(__assign({}, notice.cgiData), (0, util_1$3.formatCGIData)(headers, 'HTTP_')), this.config.filters);
1020
+ var headers = (0, util_1$4.filter)(notice.headers, this.config.filters) || {};
1021
+ var cgiData = (0, util_1$4.filter)(__assign(__assign({}, notice.cgiData), (0, util_1$4.formatCGIData)(headers, 'HTTP_')), this.config.filters);
1022
1022
  return {
1023
1023
  notifier: notifier,
1024
1024
  breadcrumbs: {
@@ -1031,16 +1031,16 @@ var Client = /** @class */ (function () {
1031
1031
  backtrace: notice.backtrace,
1032
1032
  fingerprint: notice.fingerprint,
1033
1033
  tags: notice.tags,
1034
- causes: (0, util_1$3.getCauses)(notice),
1034
+ causes: (0, util_1$4.getCauses)(notice),
1035
1035
  },
1036
1036
  request: {
1037
- url: (0, util_1$3.filterUrl)(notice.url, this.config.filters),
1037
+ url: (0, util_1$4.filterUrl)(notice.url, this.config.filters),
1038
1038
  component: notice.component,
1039
1039
  action: notice.action,
1040
1040
  context: notice.context,
1041
1041
  cgi_data: cgiData,
1042
- params: (0, util_1$3.filter)(notice.params, this.config.filters) || {},
1043
- session: (0, util_1$3.filter)(notice.session, this.config.filters) || {}
1042
+ params: (0, util_1$4.filter)(notice.params, this.config.filters) || {},
1043
+ session: (0, util_1$4.filter)(notice.session, this.config.filters) || {}
1044
1044
  },
1045
1045
  server: {
1046
1046
  project_root: notice.projectRoot,
@@ -1100,6 +1100,7 @@ Object.defineProperty(types, "__esModule", { value: true });
1100
1100
  __exportStar(store, exports);
1101
1101
  exports.Types = __importStar(types);
1102
1102
  exports.Util = __importStar(util$1);
1103
+
1103
1104
  } (src));
1104
1105
 
1105
1106
  var util = {};
@@ -1147,8 +1148,8 @@ Object.defineProperty(util, "__esModule", { value: true });
1147
1148
  util.getSourceFile = util.getStats = util.fatallyLogAndExit = void 0;
1148
1149
  var os_1 = __importDefault$2(require$$0__default["default"]);
1149
1150
  var fs_1 = __importDefault$2(require$$1__default["default"]);
1150
- var util_1$2 = require$$2__default["default"];
1151
- var readFile = (0, util_1$2.promisify)(fs_1.default.readFile);
1151
+ var util_1$3 = require$$2__default["default"];
1152
+ var readFile = (0, util_1$3.promisify)(fs_1.default.readFile);
1152
1153
  function fatallyLogAndExit(err) {
1153
1154
  console.error('[Honeybadger] Exiting process due to uncaught exception');
1154
1155
  console.error(err.stack || err);
@@ -1339,9 +1340,10 @@ function removeAwsDefaultUncaughtExceptionListener() {
1339
1340
  aws_lambda.removeAwsDefaultUncaughtExceptionListener = removeAwsDefaultUncaughtExceptionListener;
1340
1341
 
1341
1342
  Object.defineProperty(uncaught_exception, "__esModule", { value: true });
1342
- var util_1$1 = util;
1343
+ var util_1$2 = util;
1343
1344
  var aws_lambda_1 = aws_lambda;
1344
- var count = 0;
1345
+ var isReporting$1 = false;
1346
+ var handlerAlreadyCalled = false;
1345
1347
  function removeAwsLambdaListener() {
1346
1348
  var isLambda = !!process.env.LAMBDA_TASK_ROOT;
1347
1349
  if (!isLambda) {
@@ -1349,6 +1351,15 @@ function removeAwsLambdaListener() {
1349
1351
  }
1350
1352
  (0, aws_lambda_1.removeAwsDefaultUncaughtExceptionListener)();
1351
1353
  }
1354
+ /**
1355
+ * If there are no other uncaughtException listeners,
1356
+ * we want to report the exception to Honeybadger and
1357
+ * mimic the default behavior of NodeJs,
1358
+ * which is to exit the process with code 1
1359
+ */
1360
+ function hasOtherUncaughtExceptionListeners() {
1361
+ return process.listeners('uncaughtException').length > 1;
1362
+ }
1352
1363
  function default_1$1() {
1353
1364
  return {
1354
1365
  load: function (client) {
@@ -1357,22 +1368,34 @@ function default_1$1() {
1357
1368
  }
1358
1369
  removeAwsLambdaListener();
1359
1370
  process.on('uncaughtException', function honeybadgerUncaughtExceptionListener(uncaughtError) {
1360
- // Prevent recursive errors
1361
- if (count > 1) {
1362
- (0, util_1$1.fatallyLogAndExit)(uncaughtError);
1371
+ if (!client.config.enableUncaught) {
1372
+ client.config.afterUncaught(uncaughtError);
1373
+ if (!hasOtherUncaughtExceptionListeners()) {
1374
+ (0, util_1$2.fatallyLogAndExit)(uncaughtError);
1375
+ }
1376
+ return;
1363
1377
  }
1364
- if (client.config.enableUncaught) {
1365
- client.notify(uncaughtError, {
1366
- afterNotify: function (_err, _notice) {
1367
- count += 1;
1368
- client.config.afterUncaught(uncaughtError);
1369
- }
1370
- });
1378
+ // report only the first error - prevent reporting recursive errors
1379
+ if (handlerAlreadyCalled) {
1380
+ if (!hasOtherUncaughtExceptionListeners()) {
1381
+ (0, util_1$2.fatallyLogAndExit)(uncaughtError);
1382
+ }
1383
+ return;
1371
1384
  }
1372
- else {
1373
- count += 1;
1374
- client.config.afterUncaught(uncaughtError);
1385
+ if (isReporting$1) {
1386
+ return;
1375
1387
  }
1388
+ isReporting$1 = true;
1389
+ client.notify(uncaughtError, {
1390
+ afterNotify: function (_err, _notice) {
1391
+ isReporting$1 = false;
1392
+ handlerAlreadyCalled = true;
1393
+ client.config.afterUncaught(uncaughtError);
1394
+ if (!hasOtherUncaughtExceptionListeners()) {
1395
+ (0, util_1$2.fatallyLogAndExit)(uncaughtError);
1396
+ }
1397
+ }
1398
+ });
1376
1399
  });
1377
1400
  }
1378
1401
  };
@@ -1382,17 +1405,39 @@ uncaught_exception.default = default_1$1;
1382
1405
  var unhandled_rejection = {};
1383
1406
 
1384
1407
  Object.defineProperty(unhandled_rejection, "__esModule", { value: true });
1408
+ var util_1$1 = util;
1409
+ var isReporting = false;
1410
+ /**
1411
+ * If there are no other unhandledRejection listeners,
1412
+ * we want to report the exception to Honeybadger and
1413
+ * mimic the default behavior of NodeJs,
1414
+ * which is to exit the process with code 1
1415
+ */
1416
+ function hasOtherUnhandledRejectionListeners() {
1417
+ return process.listeners('unhandledRejection').length > 1;
1418
+ }
1385
1419
  function default_1() {
1386
1420
  return {
1387
1421
  load: function (client) {
1388
1422
  if (!client.config.enableUnhandledRejection) {
1389
1423
  return;
1390
1424
  }
1391
- process.on('unhandledRejection', function (reason, _promise) {
1425
+ process.on('unhandledRejection', function honeybadgerUnhandledRejectionListener(reason, _promise) {
1392
1426
  if (!client.config.enableUnhandledRejection) {
1427
+ if (!hasOtherUnhandledRejectionListeners() && !isReporting) {
1428
+ (0, util_1$1.fatallyLogAndExit)(reason);
1429
+ }
1393
1430
  return;
1394
1431
  }
1395
- client.notify(reason, { component: 'unhandledRejection' });
1432
+ isReporting = true;
1433
+ client.notify(reason, { component: 'unhandledRejection' }, {
1434
+ afterNotify: function () {
1435
+ isReporting = false;
1436
+ if (!hasOtherUnhandledRejectionListeners()) {
1437
+ (0, util_1$1.fatallyLogAndExit)(reason);
1438
+ }
1439
+ }
1440
+ });
1396
1441
  });
1397
1442
  }
1398
1443
  };
@@ -1777,8 +1822,10 @@ stacked_store.StackedStore = StackedStore;
1777
1822
  (0, unhandled_rejection_1.default)()
1778
1823
  ],
1779
1824
  });
1825
+
1780
1826
  } (server$1));
1781
1827
 
1782
1828
  var server = /*@__PURE__*/getDefaultExportFromCjs(server$1);
1783
1829
 
1784
1830
  module.exports = server;
1831
+ //# sourceMappingURL=honeybadger.js.map