From ed57dcd9d5c594b8efc74bb20453dcbc7cdddb4d Mon Sep 17 00:00:00 2001 From: Thanasis Polychronakis Date: Thu, 18 Apr 2013 22:25:58 +0300 Subject: [PATCH] handling of errors on multi, now returns 'err' array type --- index.js | 12 ++++-------- test.js | 11 ++++++++++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index fcca3feba1..5f46888110 100644 --- a/index.js +++ b/index.js @@ -1011,7 +1011,7 @@ Multi.prototype.HMSET = Multi.prototype.hmset; Multi.prototype.exec = function (callback) { var self = this; - + var errors = []; // drain queue, callback will catch "QUEUED" or error // TODO - get rid of all of these anonymous functions which are elegant but slow this.queue.forEach(function (args, index) { @@ -1037,12 +1037,7 @@ Multi.prototype.exec = function (callback) { if (typeof cur[cur.length - 1] === "function") { cur[cur.length - 1](err); } else { - if (callback) { - callback(new Error(err)); - return; - } else { - throw new Error(err); - } + errors.push(new Error(err)); } self.queue.splice(index, 1); } @@ -1053,7 +1048,8 @@ Multi.prototype.exec = function (callback) { return this._client.send_command("EXEC", [], function (err, replies) { if (err) { if (callback) { - callback(new Error(err)); + errors.push(new Error(err)); + callback(errors); return; } else { throw new Error(err); diff --git a/test.js b/test.js index 1d8d6343af..07ddcf97cb 100644 --- a/test.js +++ b/test.js @@ -320,6 +320,15 @@ tests.MULTI_7 = function () { next(name); }; + +tests.MULTI_EXCEPTION_1 = function() { + client.multi().set("foo").exec(function (err, reply) { + /* ... */ + console.log('CB:', arguments); + }); + // [Error: Error: ERR wrong number of arguments for 'set' command] +}; + tests.FWD_ERRORS_1 = function () { var name = "FWD_ERRORS_1"; @@ -615,7 +624,7 @@ tests.detect_buffers = function () { assert.strictEqual("", reply[0].inspect(), name); assert.strictEqual("", reply[1].inspect(), name); }); - + // array of strings with undefined values (repro #344) detect_client.hmget("hash key 2", "key 3", "key 4", function(err, reply) { assert.strictEqual(null, err, name);