From ddc7aebd112ab4f0a50cf096d5f84276ec07b2a6 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Tue, 24 Jan 2017 23:41:37 -0700 Subject: [PATCH] fix: filter out _kareemIgnored args for error handlers re: Automattic/mongoose#4925 --- index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 16e7e07..4dfed03 100644 --- a/index.js +++ b/index.js @@ -132,13 +132,17 @@ Kareem.prototype.execPost = function(name, context, args, options, callback) { var post = posts[currentPost]; var numArgs = 0; var argLength = args.length; + var newArgs = []; for (var i = 0; i < argLength; ++i) { numArgs += args[i] && args[i]._kareemIgnore ? 0 : 1; + if (!args[i] || !args[i]._kareemIgnore) { + newArgs.push(args[i]); + } } if (firstError) { if (post.length === numArgs + 2) { - post.apply(context, [firstError].concat(args).concat(function(error) { + post.apply(context, [firstError].concat(newArgs).concat(function(error) { if (error) { firstError = error; } @@ -162,7 +166,7 @@ Kareem.prototype.execPost = function(name, context, args, options, callback) { return next(); } if (post.length === numArgs + 1) { - post.apply(context, args.concat(function(error) { + post.apply(context, newArgs.concat(function(error) { if (error) { firstError = error; return next(); @@ -175,7 +179,7 @@ Kareem.prototype.execPost = function(name, context, args, options, callback) { next(); })); } else { - post.apply(context, args); + post.apply(context, newArgs); if (++currentPost >= numPosts) { return callback.apply(null, [null].concat(args));