@honeybadger-io/js 6.3.0 → 6.4.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.
@@ -282,6 +282,9 @@
282
282
  function makeBacktrace(stack, filterHbSourceCode, logger) {
283
283
  if (filterHbSourceCode === void 0) { filterHbSourceCode = false; }
284
284
  if (logger === void 0) { logger = console; }
285
+ if (!stack) {
286
+ return [];
287
+ }
285
288
  try {
286
289
  var backtrace = stackTraceParser
287
290
  .parse(stack)
@@ -398,14 +401,20 @@
398
401
  }
399
402
  exports.getSourceForBacktrace = getSourceForBacktrace;
400
403
  function runBeforeNotifyHandlers(notice, handlers) {
404
+ var results = [];
401
405
  var result = true;
402
406
  for (var i = 0, len = handlers.length; i < len; i++) {
403
407
  var handler = handlers[i];
404
- if (handler(notice) === false) {
408
+ var handlerResult = handler(notice);
409
+ if (handlerResult === false) {
405
410
  result = false;
406
411
  }
412
+ results.push(handlerResult);
407
413
  }
408
- return result;
414
+ return {
415
+ results: results,
416
+ result: result
417
+ };
409
418
  }
410
419
  exports.runBeforeNotifyHandlers = runBeforeNotifyHandlers;
411
420
  function runAfterNotifyHandlers(notice, handlers, error) {
@@ -794,6 +803,42 @@
794
803
  };
795
804
  return __assign.apply(this, arguments);
796
805
  };
806
+ var __awaiter$1 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
807
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
808
+ return new (P || (P = Promise))(function (resolve, reject) {
809
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
810
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
811
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
812
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
813
+ });
814
+ };
815
+ var __generator$1 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
816
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
817
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
818
+ function verb(n) { return function (v) { return step([n, v]); }; }
819
+ function step(op) {
820
+ if (f) throw new TypeError("Generator is already executing.");
821
+ while (_) try {
822
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
823
+ if (y = 0, t) op = [op[0] & 2, t.value];
824
+ switch (op[0]) {
825
+ case 0: case 1: t = op; break;
826
+ case 4: _.label++; return { value: op[1], done: false };
827
+ case 5: _.label++; y = op[1]; op = [0]; continue;
828
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
829
+ default:
830
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
831
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
832
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
833
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
834
+ if (t[2]) _.ops.pop();
835
+ _.trys.pop(); continue;
836
+ }
837
+ op = body.call(thisArg, _);
838
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
839
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
840
+ }
841
+ };
797
842
  Object.defineProperty(client, "__esModule", { value: true });
798
843
  client.Client = void 0;
799
844
  var util_1$6 = util$1;
@@ -812,7 +857,7 @@
812
857
  this.__notifier = {
813
858
  name: '@honeybadger-io/core',
814
859
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/core',
815
- version: '6.3.0'
860
+ version: '6.4.0'
816
861
  };
817
862
  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);
818
863
  this.__initStore();
@@ -825,6 +870,13 @@
825
870
  Client.prototype.getNotifier = function () {
826
871
  return this.__notifier;
827
872
  };
873
+ /**
874
+ * CAREFUL: When adding a new notifier or updating the name of an existing notifier,
875
+ * the Honeybadger rails project may need its mappings updated.
876
+ * See https://github.com/honeybadger-io/honeybadger/blob/master/app/presenters/breadcrumbs_presenter.rb
877
+ * https://github.com/honeybadger-io/honeybadger/blob/master/app/models/parser/java_script.rb
878
+ * https://github.com/honeybadger-io/honeybadger/blob/master/app/models/language.rb
879
+ **/
828
880
  Client.prototype.setNotifier = function (notifier) {
829
881
  this.__notifier = notifier;
830
882
  };
@@ -873,81 +925,26 @@
873
925
  var _this = this;
874
926
  if (name === void 0) { name = undefined; }
875
927
  if (extra === void 0) { extra = undefined; }
876
- var preConditionError = null;
877
928
  var notice = this.makeNotice(noticeable, name, extra);
878
- if (!notice) {
879
- this.logger.debug('failed to build error report');
880
- preConditionError = new Error('failed to build error report');
881
- }
882
- if (!preConditionError && this.config.reportData === false) {
883
- this.logger.debug('skipping error report: honeybadger.js is disabled', notice);
884
- preConditionError = new Error('honeybadger.js is disabled');
885
- }
886
- if (!preConditionError && this.__developmentMode()) {
887
- this.logger.log('honeybadger.js is in development mode; the following error report will be sent in production.', notice);
888
- preConditionError = new Error('honeybadger.js is in development mode');
889
- }
890
- if (!preConditionError && !this.config.apiKey) {
891
- this.logger.warn('could not send error report: no API key has been configured', notice);
892
- preConditionError = new Error('missing API key');
893
- }
894
929
  // we need to have the source file data before the beforeNotifyHandlers,
895
930
  // in case they modify them
896
931
  var sourceCodeData = notice && notice.backtrace ? notice.backtrace.map(function (trace) { return (0, util_1$6.shallowClone)(trace); }) : null;
897
- var beforeNotifyResult = (0, util_1$6.runBeforeNotifyHandlers)(notice, this.__beforeNotifyHandlers);
898
- if (!preConditionError && !beforeNotifyResult) {
899
- this.logger.debug('skipping error report: beforeNotify handlers returned false', notice);
900
- preConditionError = new Error('beforeNotify handlers returned false');
901
- }
902
- if (preConditionError) {
903
- (0, util_1$6.runAfterNotifyHandlers)(notice, this.__afterNotifyHandlers, preConditionError);
932
+ var preConditionsResult = this.__runPreconditions(notice);
933
+ if (preConditionsResult instanceof Error) {
934
+ (0, util_1$6.runAfterNotifyHandlers)(notice, this.__afterNotifyHandlers, preConditionsResult);
904
935
  return false;
905
936
  }
906
- this.addBreadcrumb('Honeybadger Notice', {
907
- category: 'notice',
908
- metadata: {
909
- message: notice.message,
910
- name: notice.name,
911
- stack: notice.stack
912
- }
913
- });
914
- var breadcrumbs = this.__store.getContents('breadcrumbs');
915
- notice.__breadcrumbs = this.config.breadcrumbsEnabled ? breadcrumbs : [];
916
- (0, util_1$6.getSourceForBacktrace)(sourceCodeData, this.__getSourceFileHandler)
917
- .then(function (sourcePerTrace) {
918
- sourcePerTrace.forEach(function (source, index) {
919
- notice.backtrace[index].source = source;
920
- });
921
- var payload = _this.__buildPayload(notice);
922
- _this.__transport
923
- .send({
924
- headers: {
925
- 'X-API-Key': _this.config.apiKey,
926
- 'Content-Type': 'application/json',
927
- 'Accept': 'text/json, application/json'
928
- },
929
- method: 'POST',
930
- endpoint: (0, util_1$6.endpoint)(_this.config.endpoint, '/v1/notices/js'),
931
- maxObjectDepth: _this.config.maxObjectDepth,
932
- logger: _this.logger,
933
- }, payload)
934
- .then(function (res) {
935
- if (res.statusCode !== 201) {
936
- (0, util_1$6.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, new Error("Bad HTTP response: ".concat(res.statusCode)));
937
- _this.logger.warn("Error report failed: unknown response from server. code=".concat(res.statusCode));
938
- return;
937
+ if (preConditionsResult instanceof Promise) {
938
+ preConditionsResult.then(function (result) {
939
+ if (result instanceof Error) {
940
+ (0, util_1$6.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, result);
941
+ return false;
939
942
  }
940
- var uuid = JSON.parse(res.body).id;
941
- (0, util_1$6.runAfterNotifyHandlers)((0, util_1$6.merge)(notice, {
942
- id: uuid
943
- }), _this.__afterNotifyHandlers);
944
- _this.logger.info("Error report sent \u26A1 https://app.honeybadger.io/notice/".concat(uuid));
945
- })
946
- .catch(function (err) {
947
- _this.logger.error('Error report failed: an unknown error occurred.', "message=".concat(err.message));
948
- (0, util_1$6.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, err);
943
+ return _this.__send(notice, sourceCodeData);
949
944
  });
950
- });
945
+ return true;
946
+ }
947
+ this.__send(notice, sourceCodeData).catch(function (_err) { });
951
948
  return true;
952
949
  };
953
950
  /**
@@ -1112,6 +1109,101 @@
1112
1109
  }
1113
1110
  return tags.toString().split(TAG_SEPARATOR).filter(function (tag) { return NOT_BLANK.test(tag); });
1114
1111
  };
1112
+ Client.prototype.__runPreconditions = function (notice) {
1113
+ var _this = this;
1114
+ var preConditionError = null;
1115
+ if (!notice) {
1116
+ this.logger.debug('failed to build error report');
1117
+ preConditionError = new Error('failed to build error report');
1118
+ }
1119
+ if (this.config.reportData === false) {
1120
+ this.logger.debug('skipping error report: honeybadger.js is disabled', notice);
1121
+ preConditionError = new Error('honeybadger.js is disabled');
1122
+ }
1123
+ if (this.__developmentMode()) {
1124
+ this.logger.log('honeybadger.js is in development mode; the following error report will be sent in production.', notice);
1125
+ preConditionError = new Error('honeybadger.js is in development mode');
1126
+ }
1127
+ if (!this.config.apiKey) {
1128
+ this.logger.warn('could not send error report: no API key has been configured', notice);
1129
+ preConditionError = new Error('missing API key');
1130
+ }
1131
+ var beforeNotifyResult = (0, util_1$6.runBeforeNotifyHandlers)(notice, this.__beforeNotifyHandlers);
1132
+ if (!preConditionError && !beforeNotifyResult.result) {
1133
+ this.logger.debug('skipping error report: one or more beforeNotify handlers returned false', notice);
1134
+ preConditionError = new Error('beforeNotify handlers returned false');
1135
+ }
1136
+ if (beforeNotifyResult.results.length && beforeNotifyResult.results.some(function (result) { return result instanceof Promise; })) {
1137
+ return Promise.allSettled(beforeNotifyResult.results)
1138
+ .then(function (results) {
1139
+ if (!preConditionError && (results.some(function (result) { return result.status === 'rejected' || result.value === false; }))) {
1140
+ _this.logger.debug('skipping error report: one or more beforeNotify handlers returned false', notice);
1141
+ preConditionError = new Error('beforeNotify handlers (async) returned false');
1142
+ }
1143
+ if (preConditionError) {
1144
+ return preConditionError;
1145
+ }
1146
+ });
1147
+ }
1148
+ return preConditionError;
1149
+ };
1150
+ Client.prototype.__send = function (notice, originalBacktrace) {
1151
+ var _this = this;
1152
+ if (this.config.breadcrumbsEnabled) {
1153
+ this.addBreadcrumb('Honeybadger Notice', {
1154
+ category: 'notice',
1155
+ metadata: {
1156
+ message: notice.message,
1157
+ name: notice.name,
1158
+ stack: notice.stack
1159
+ }
1160
+ });
1161
+ notice.__breadcrumbs = this.__store.getContents('breadcrumbs');
1162
+ }
1163
+ else {
1164
+ notice.__breadcrumbs = [];
1165
+ }
1166
+ return (0, util_1$6.getSourceForBacktrace)(originalBacktrace, this.__getSourceFileHandler)
1167
+ .then(function (sourcePerTrace) { return __awaiter$1(_this, void 0, void 0, function () {
1168
+ var payload;
1169
+ return __generator$1(this, function (_a) {
1170
+ sourcePerTrace.forEach(function (source, index) {
1171
+ notice.backtrace[index].source = source;
1172
+ });
1173
+ payload = this.__buildPayload(notice);
1174
+ return [2 /*return*/, this.__transport
1175
+ .send({
1176
+ headers: {
1177
+ 'X-API-Key': this.config.apiKey,
1178
+ 'Content-Type': 'application/json',
1179
+ 'Accept': 'text/json, application/json'
1180
+ },
1181
+ method: 'POST',
1182
+ endpoint: (0, util_1$6.endpoint)(this.config.endpoint, '/v1/notices/js'),
1183
+ maxObjectDepth: this.config.maxObjectDepth,
1184
+ logger: this.logger,
1185
+ }, payload)];
1186
+ });
1187
+ }); })
1188
+ .then(function (res) {
1189
+ if (res.statusCode !== 201) {
1190
+ (0, util_1$6.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, new Error("Bad HTTP response: ".concat(res.statusCode)));
1191
+ _this.logger.warn("Error report failed: unknown response from server. code=".concat(res.statusCode));
1192
+ return false;
1193
+ }
1194
+ var uuid = JSON.parse(res.body).id;
1195
+ (0, util_1$6.runAfterNotifyHandlers)((0, util_1$6.merge)(notice, {
1196
+ id: uuid
1197
+ }), _this.__afterNotifyHandlers);
1198
+ _this.logger.info("Error report sent \u26A1 https://app.honeybadger.io/notice/".concat(uuid));
1199
+ return true;
1200
+ })
1201
+ .catch(function (err) {
1202
+ _this.logger.error('Error report failed: an unknown error occurred.', "message=".concat(err.message));
1203
+ (0, util_1$6.runAfterNotifyHandlers)(notice, _this.__afterNotifyHandlers, err);
1204
+ return false;
1205
+ });
1206
+ };
1115
1207
  return Client;
1116
1208
  }());
1117
1209
  client.Client = Client;
@@ -2056,7 +2148,6 @@
2056
2148
  if (notice) {
2057
2149
  _this.__lastNoticeId = notice.id;
2058
2150
  }
2059
- return true;
2060
2151
  }
2061
2152
  ];
2062
2153
  return _this;
@@ -2234,7 +2325,7 @@
2234
2325
  var NOTIFIER = {
2235
2326
  name: '@honeybadger-io/js',
2236
2327
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/js',
2237
- version: '6.3.0'
2328
+ version: '6.4.0'
2238
2329
  };
2239
2330
  singleton.setNotifier(NOTIFIER);
2240
2331
  var core_2 = src;