Skip to content

Commit

Permalink
fix Automattic/mongoose#2553 - use null instead of undefined for err
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jan 4, 2015
1 parent 92c12a7 commit 9157b48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
16 changes: 8 additions & 8 deletions index.js
Expand Up @@ -15,7 +15,7 @@ Kareem.prototype.execPre = function(name, context, callback) {

if (!numPres) {
return process.nextTick(function() {
callback();
callback(null);
});
}

Expand Down Expand Up @@ -50,8 +50,8 @@ Kareem.prototype.execPre = function(name, context, callback) {
}

if (0 === --numAsyncPres) {
return callback();
}
return callback(null);
}
});
} else if (pre.fn.length > 0) {
pre.fn.call(context, function(error) {
Expand All @@ -68,7 +68,7 @@ Kareem.prototype.execPre = function(name, context, callback) {
// Leave parallel hooks to run
return;
} else {
return callback();
return callback(null);
}
}

Expand All @@ -82,7 +82,7 @@ Kareem.prototype.execPre = function(name, context, callback) {
return;
} else {
return process.nextTick(function() {
callback()
callback(null);
});
}
}
Expand All @@ -100,7 +100,7 @@ Kareem.prototype.execPost = function(name, context, args, callback) {

if (!numPosts) {
return process.nextTick(function() {
callback.apply(null, [undefined].concat(args));
callback.apply(null, [null].concat(args));
});
}

Expand All @@ -114,7 +114,7 @@ Kareem.prototype.execPost = function(name, context, args, callback) {
}

if (++currentPost >= numPosts) {
return callback.apply(null, [undefined].concat(args));
return callback.apply(null, [null].concat(args));
}

next();
Expand All @@ -123,7 +123,7 @@ Kareem.prototype.execPost = function(name, context, args, callback) {
post.apply(context, args);

if (++currentPost >= numPosts) {
return callback.apply(null, [undefined].concat(args));
return callback.apply(null, [null].concat(args));
}

next();
Expand Down
7 changes: 5 additions & 2 deletions test/examples.test.js
Expand Up @@ -74,7 +74,8 @@ describe('pre hooks', function() {
++count2;
});

hooks.execPre('cook', null, function() {
hooks.execPre('cook', null, function(error) {
assert.equal(null, error);
assert.equal(1, count1);
assert.equal(1, count2);
done();
Expand All @@ -97,7 +98,8 @@ describe('pre hooks', function() {
var obj = { bacon: 0, eggs: 0 };

// In the pre hooks, `this` will refer to `obj`
hooks.execPre('cook', obj, function() {
hooks.execPre('cook', obj, function(error) {
assert.equal(null, error);
assert.equal(3, obj.bacon);
assert.equal(4, obj.eggs);
done();
Expand Down Expand Up @@ -240,6 +242,7 @@ describe('wrap()', function() {
var args = [obj];
args.push(function(error, result) {
assert.ifError(error);
assert.equal(null, error);
assert.equal(3, obj.bacon);
assert.equal(4, obj.eggs);
assert.equal(false, obj.waffles);
Expand Down

0 comments on commit 9157b48

Please sign in to comment.