Skip to content

Commit 08a8eed

Browse files
committed
Revert "Client to emit errors now instead of throwing them asynchronously where they're uncatchable."
This reverts commit 6a3ccf6.
1 parent a8403a0 commit 08a8eed

File tree

2 files changed

+20
-74
lines changed

2 files changed

+20
-74
lines changed

index.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ RedisClient.prototype.flush_and_error = function (message) {
154154
try {
155155
command_obj.callback(error);
156156
} catch (callback_err) {
157-
this.emit("error", callback_err);
157+
process.nextTick(function () {
158+
throw callback_err;
159+
});
158160
}
159161
}
160162
}
@@ -166,7 +168,9 @@ RedisClient.prototype.flush_and_error = function (message) {
166168
try {
167169
command_obj.callback(error);
168170
} catch (callback_err) {
169-
this.emit("error", callback_err);
171+
process.nextTick(function () {
172+
throw callback_err;
173+
});
170174
}
171175
}
172176
}
@@ -566,18 +570,24 @@ RedisClient.prototype.return_error = function (err) {
566570
try {
567571
command_obj.callback(err);
568572
} catch (callback_err) {
569-
this.emit("error", callback_err);
573+
// if a callback throws an exception, re-throw it on a new stack so the parser can keep going
574+
process.nextTick(function () {
575+
throw callback_err;
576+
});
570577
}
571578
} else {
572579
console.log("node_redis: no callback to send error: " + err.message);
573-
this.emit("error", err);
580+
// this will probably not make it anywhere useful, but we might as well throw
581+
process.nextTick(function () {
582+
throw err;
583+
});
574584
}
575585
};
576586

577587
// if a callback throws an exception, re-throw it on a new stack so the parser can keep going.
578588
// if a domain is active, emit the error on the domain, which will serve the same function.
579589
// put this try/catch in its own function because V8 doesn't optimize this well yet.
580-
function try_callback(client, callback, reply) {
590+
function try_callback(callback, reply) {
581591
try {
582592
callback(null, reply);
583593
} catch (err) {
@@ -588,7 +598,9 @@ function try_callback(client, callback, reply) {
588598
currDomain.exit();
589599
}
590600
} else {
591-
client.emit("error", err);
601+
process.nextTick(function () {
602+
throw err;
603+
});
592604
}
593605
}
594606
}
@@ -670,7 +682,7 @@ RedisClient.prototype.return_reply = function (reply) {
670682
reply = reply_to_object(reply);
671683
}
672684

673-
try_callback(this, command_obj.callback, reply);
685+
try_callback(command_obj.callback, reply);
674686
} else if (exports.debug_mode) {
675687
console.log("no callback for reply: " + (reply && reply.toString && reply.toString()));
676688
}
@@ -696,7 +708,7 @@ RedisClient.prototype.return_reply = function (reply) {
696708
// reply[1] can be null
697709
var reply1String = (reply[1] === null) ? null : reply[1].toString();
698710
if (command_obj && typeof command_obj.callback === "function") {
699-
try_callback(this, command_obj.callback, reply1String);
711+
try_callback(command_obj.callback, reply1String);
700712
}
701713
this.emit(type, reply1String, reply[2]); // channel, count
702714
} else {

test.js

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -402,72 +402,6 @@ tests.FWD_ERRORS_1 = function () {
402402
}, 150);
403403
};
404404

405-
tests.FWD_ERRORS_2 = function () {
406-
var name = "FWD_ERRORS_2";
407-
408-
var toThrow = new Error("Forced exception");
409-
var recordedError = null;
410-
411-
var originalHandler = client.listeners("error").pop();
412-
client.removeAllListeners("error");
413-
client.once("error", function (err) {
414-
recordedError = err;
415-
});
416-
417-
client.get("no_such_key", function (err, reply) {
418-
throw toThrow;
419-
});
420-
421-
setTimeout(function () {
422-
client.listeners("error").push(originalHandler);
423-
assert.equal(recordedError, toThrow, "Should have caught our forced exception");
424-
next(name);
425-
}, 150);
426-
};
427-
428-
tests.FWD_ERRORS_3 = function () {
429-
var name = "FWD_ERRORS_3";
430-
431-
var recordedError = null;
432-
433-
var originalHandler = client.listeners("error").pop();
434-
client.removeAllListeners("error");
435-
client.once("error", function (err) {
436-
recordedError = err;
437-
});
438-
439-
client.send_command("no_such_command", []);
440-
441-
setTimeout(function () {
442-
client.listeners("error").push(originalHandler);
443-
assert.ok(recordedError instanceof Error);
444-
next(name);
445-
}, 150);
446-
};
447-
448-
tests.FWD_ERRORS_4 = function () {
449-
var name = "FWD_ERRORS_4";
450-
451-
var toThrow = new Error("Forced exception");
452-
var recordedError = null;
453-
454-
var originalHandler = client.listeners("error").pop();
455-
client.removeAllListeners("error");
456-
client.once("error", function (err) {
457-
recordedError = err;
458-
});
459-
460-
client.send_command("no_such_command", [], function () {
461-
throw toThrow;
462-
});
463-
464-
setTimeout(function () {
465-
client.listeners("error").push(originalHandler);
466-
assert.equal(recordedError, toThrow, "Should have caught our forced exception");
467-
next(name);
468-
}, 150);
469-
};
470-
471405
tests.EVAL_1 = function () {
472406
var name = "EVAL_1";
473407

0 commit comments

Comments
 (0)