Skip to content

Commit

Permalink
Removed last error handler fallback, which makes the error handler th…
Browse files Browse the repository at this point in the history
…e target method. Instead just throw an error if you get to that point.
  • Loading branch information
bnoguchi committed Jun 14, 2011
1 parent 5459a55 commit c145d60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
1 change: 0 additions & 1 deletion hooks.js
Expand Up @@ -91,7 +91,6 @@ module.exports = {
if (errorCb) return errorCb(err); if (errorCb) return errorCb(err);
if ('function' == typeof lastArg) if ('function' == typeof lastArg)
return lastArg(err); return lastArg(err);
if (fn.length > 0) return fn.call(self, err);
throw err; throw err;
} }
return _next.apply(this, arguments); return _next.apply(this, arguments);
Expand Down
32 changes: 11 additions & 21 deletions test.js
Expand Up @@ -208,7 +208,7 @@ module.exports = {
counter.should.equal(1); counter.should.equal(1);
should.deepEqual(undefined, a.value); should.deepEqual(undefined, a.value);
}, },
'should fall back last to the hook method as the error handler': function () { 'should fall back last to throwing the error': function () {
var A = function () {}; var A = function () {};
_.extend(A, hooks); _.extend(A, hooks);
var counter = 0; var counter = 0;
Expand All @@ -220,26 +220,16 @@ module.exports = {
next(new Error()); next(new Error());
}); });
var a = new A(); var a = new A();
a.save(); var didCatch = false;
counter.should.equal(1); try {
assert.equal(typeof a.value, 'undefined'); a.save();
}, } catch (e) {
'should have access to the object scope when falling back last to the hook method as the error handler': function () { didCatch = true;
var A = function () { e.should.be.an.instanceof(Error);
this.counter = 0; counter.should.equal(0);
}; assert.equal(typeof a.value, 'undefined');
_.extend(A, hooks); }
A.hook('save', function (err) { didCatch.should.be.true;
if (err instanceof Error) return this.counter++;
this.value = 1;
});
A.pre('save', true, function (next, done) {
next(new Error());
});
var a = new A();
a.save();
a.counter.should.equal(1);
assert.equal(typeof a.value, 'undefined');
}, },
"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 () { "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 () {
var A = function () {}; var A = function () {};
Expand Down

0 comments on commit c145d60

Please sign in to comment.