Skip to content

Commit ed57dcd

Browse files
committed
handling of errors on multi, now returns 'err' array type
1 parent c7633bf commit ed57dcd

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

index.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ Multi.prototype.HMSET = Multi.prototype.hmset;
10111011

10121012
Multi.prototype.exec = function (callback) {
10131013
var self = this;
1014-
1014+
var errors = [];
10151015
// drain queue, callback will catch "QUEUED" or error
10161016
// TODO - get rid of all of these anonymous functions which are elegant but slow
10171017
this.queue.forEach(function (args, index) {
@@ -1037,12 +1037,7 @@ Multi.prototype.exec = function (callback) {
10371037
if (typeof cur[cur.length - 1] === "function") {
10381038
cur[cur.length - 1](err);
10391039
} else {
1040-
if (callback) {
1041-
callback(new Error(err));
1042-
return;
1043-
} else {
1044-
throw new Error(err);
1045-
}
1040+
errors.push(new Error(err));
10461041
}
10471042
self.queue.splice(index, 1);
10481043
}
@@ -1053,7 +1048,8 @@ Multi.prototype.exec = function (callback) {
10531048
return this._client.send_command("EXEC", [], function (err, replies) {
10541049
if (err) {
10551050
if (callback) {
1056-
callback(new Error(err));
1051+
errors.push(new Error(err));
1052+
callback(errors);
10571053
return;
10581054
} else {
10591055
throw new Error(err);

test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,15 @@ tests.MULTI_7 = function () {
320320
next(name);
321321
};
322322

323+
324+
tests.MULTI_EXCEPTION_1 = function() {
325+
client.multi().set("foo").exec(function (err, reply) {
326+
/* ... */
327+
console.log('CB:', arguments);
328+
});
329+
// [Error: Error: ERR wrong number of arguments for 'set' command]
330+
};
331+
323332
tests.FWD_ERRORS_1 = function () {
324333
var name = "FWD_ERRORS_1";
325334

@@ -615,7 +624,7 @@ tests.detect_buffers = function () {
615624
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply[0].inspect(), name);
616625
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply[1].inspect(), name);
617626
});
618-
627+
619628
// array of strings with undefined values (repro #344)
620629
detect_client.hmget("hash key 2", "key 3", "key 4", function(err, reply) {
621630
assert.strictEqual(null, err, name);

0 commit comments

Comments
 (0)