kareem 2.3.2 → 2.3.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ <a name="2.3.3"></a>
4
+ ## 2.3.3 (2021-12-26)
5
+
6
+ * fix: handle sync errors in `wrap()`
7
+
3
8
  <a name="2.3.2"></a>
4
9
  ## 2.3.2 (2020-12-08)
5
10
 
package/index.js CHANGED
@@ -276,7 +276,12 @@ Kareem.prototype.wrap = function(name, fn, context, args, options) {
276
276
 
277
277
  const end = (typeof lastArg === 'function' ? args.length - 1 : args.length);
278
278
  const numParameters = fn.length;
279
- const ret = fn.apply(context, args.slice(0, end).concat(_cb));
279
+ let ret;
280
+ try {
281
+ ret = fn.apply(context, args.slice(0, end).concat(_cb));
282
+ } catch (err) {
283
+ return _cb(err);
284
+ }
280
285
 
281
286
  if (checkForPromise) {
282
287
  if (ret != null && typeof ret.then === 'function') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kareem",
3
- "version": "2.3.2",
3
+ "version": "2.3.3",
4
4
  "description": "Next-generation take on pre/post function hooks",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test/wrap.test.js CHANGED
@@ -319,6 +319,30 @@ describe('wrap()', function() {
319
319
  25);
320
320
  });
321
321
 
322
+ it('catches sync errors', function(done) {
323
+ hooks.pre('cook', function(done) {
324
+ done();
325
+ });
326
+
327
+ hooks.post('cook', function(callback) {
328
+ callback();
329
+ });
330
+
331
+ var args = [];
332
+ args.push(function(error) {
333
+ assert.equal(error.message, 'oops!');
334
+ done();
335
+ });
336
+
337
+ hooks.wrap(
338
+ 'cook',
339
+ function() {
340
+ throw new Error('oops!');
341
+ },
342
+ null,
343
+ args);
344
+ });
345
+
322
346
  it('sync wrappers', function() {
323
347
  var calledPre = 0;
324
348
  var calledFn = 0;