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 +5 -0
- package/index.js +6 -1
- package/package.json +1 -1
- package/test/wrap.test.js +24 -0
package/CHANGELOG.md
CHANGED
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
|
-
|
|
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
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;
|