Skip to content

Commit c145d60

Browse files
committed
Removed last error handler fallback, which makes the error handler the target method. Instead just throw an error if you get to that point.
1 parent 5459a55 commit c145d60

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

hooks.js

Lines changed: 0 additions & 1 deletion
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -91,7 +91,6 @@ module.exports = {
91
if (errorCb) return errorCb(err);
91
if (errorCb) return errorCb(err);
92
if ('function' == typeof lastArg)
92
if ('function' == typeof lastArg)
93
return lastArg(err);
93
return lastArg(err);
94-
if (fn.length > 0) return fn.call(self, err);
95
throw err;
94
throw err;
96
}
95
}
97
return _next.apply(this, arguments);
96
return _next.apply(this, arguments);

test.js

Lines changed: 11 additions & 21 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -208,7 +208,7 @@ module.exports = {
208
counter.should.equal(1);
208
counter.should.equal(1);
209
should.deepEqual(undefined, a.value);
209
should.deepEqual(undefined, a.value);
210
},
210
},
211-
'should fall back last to the hook method as the error handler': function () {
211+
'should fall back last to throwing the error': function () {
212
var A = function () {};
212
var A = function () {};
213
_.extend(A, hooks);
213
_.extend(A, hooks);
214
var counter = 0;
214
var counter = 0;
@@ -220,26 +220,16 @@ module.exports = {
220
next(new Error());
220
next(new Error());
221
});
221
});
222
var a = new A();
222
var a = new A();
223-
a.save();
223+
var didCatch = false;
224-
counter.should.equal(1);
224+
try {
225-
assert.equal(typeof a.value, 'undefined');
225+
a.save();
226-
},
226+
} catch (e) {
227-
'should have access to the object scope when falling back last to the hook method as the error handler': function () {
227+
didCatch = true;
228-
var A = function () {
228+
e.should.be.an.instanceof(Error);
229-
this.counter = 0;
229+
counter.should.equal(0);
230-
};
230+
assert.equal(typeof a.value, 'undefined');
231-
_.extend(A, hooks);
231+
}
232-
A.hook('save', function (err) {
232+
didCatch.should.be.true;
233-
if (err instanceof Error) return this.counter++;
234-
this.value = 1;
235-
});
236-
A.pre('save', true, function (next, done) {
237-
next(new Error());
238-
});
239-
var a = new A();
240-
a.save();
241-
a.counter.should.equal(1);
242-
assert.equal(typeof a.value, 'undefined');
243
},
233
},
244
"should proceed without mutating arguments if `next(null)` is called in a serial pre, and the last argument of the target method is a callback with node-like signature function (err, obj) {...} or function (err) {...}": function () {
234
"should proceed without mutating arguments if `next(null)` is called in a serial pre, and the last argument of the target method is a callback with node-like signature function (err, obj) {...} or function (err) {...}": function () {
245
var A = function () {};
235
var A = function () {};

0 commit comments

Comments
 (0)