1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

Fix error messages being manipulated. Fixes #695

This commit is contained in:
Ruben Bridgewater
2015-09-20 18:53:57 +02:00
parent 91955af389
commit 1f121fa6e2
2 changed files with 21 additions and 9 deletions

View File

@@ -91,8 +91,8 @@ RedisClient.prototype.install_stream_listeners = function() {
self.reply_parser.execute(buffer_from_socket); self.reply_parser.execute(buffer_from_socket);
}); });
this.stream.on("error", function (msg) { this.stream.on("error", function (err) {
self.on_error(msg.message); self.on_error(err);
}); });
this.stream.on("close", function () { this.stream.on("close", function () {
@@ -148,19 +148,18 @@ RedisClient.prototype.flush_and_error = function (error) {
this.command_queue = new Queue(); this.command_queue = new Queue();
}; };
RedisClient.prototype.on_error = function (msg) { RedisClient.prototype.on_error = function (err) {
if (this.closing) { if (this.closing) {
return; return;
} }
var message = "Redis connection to " + this.address + " failed - " + msg; err.message = "Redis connection to " + this.address + " failed - " + err.message;
debug(message); debug(err.message);
this.connected = false; this.connected = false;
this.ready = false; this.ready = false;
this.emit("error", err);
this.emit("error", new Error(message));
// "error" events get turned into exceptions if they aren't listened for. If the user handled this error // "error" events get turned into exceptions if they aren't listened for. If the user handled this error
// then we should try to reconnect. // then we should try to reconnect.
this.connection_gone("error"); this.connection_gone("error");
@@ -346,7 +345,8 @@ RedisClient.prototype.on_info_cmd = function (err, res) {
var line, retry_time, parts, sub_parts; var line, retry_time, parts, sub_parts;
if (err) { if (err) {
return self.emit("error", new Error("Ready check failed: " + err.message)); err.message = "Ready check failed: " + err.message;
return self.emit("error", err);
} }
for (i = 0; i < lines.length; i++) { for (i = 0; i < lines.length; i++) {

View File

@@ -765,6 +765,12 @@ describe("The node_redis client", function () {
assert(i, 3); assert(i, 3);
assert.strictEqual(client.offline_queue.length, 0); assert.strictEqual(client.offline_queue.length, 0);
done(); done();
} else {
assert.equal(err.code, 'ECONNREFUSED');
assert.equal(err.errno, 'ECONNREFUSED');
assert.equal(err.syscall, 'connect');
assert.equal(err.address, '127.0.0.1');
assert.equal(err.port, 9999);
} }
}); });
@@ -785,7 +791,7 @@ describe("The node_redis client", function () {
}); });
describe('false', function () { describe('false', function () {
it("does emit an error and does not enqueues operation", function (done) { it("emit an error and does not enqueues operation", function (done) {
var client = redis.createClient(9999, null, { var client = redis.createClient(9999, null, {
parser: parser, parser: parser,
max_attempts: 0, max_attempts: 0,
@@ -840,6 +846,12 @@ describe("The node_redis client", function () {
if (/Redis connection in broken state:/.test(err.message)) { if (/Redis connection in broken state:/.test(err.message)) {
assert.equal(client.command_queue.length, 0); assert.equal(client.command_queue.length, 0);
done(); done();
} else {
assert.equal(err.code, 'ECONNREFUSED');
assert.equal(err.errno, 'ECONNREFUSED');
assert.equal(err.syscall, 'connect');
assert.equal(err.address, '127.0.0.2');
assert.equal(err.port, 6370);
} }
}); });
}); });