Skip to content

Commit

Permalink
Fix error messages being manipulated. Fixes #695
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Bridgewater committed Sep 20, 2015
1 parent 91955af commit 1f121fa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ RedisClient.prototype.install_stream_listeners = function() {
self.reply_parser.execute(buffer_from_socket);
});

this.stream.on("error", function (msg) {
self.on_error(msg.message);
this.stream.on("error", function (err) {
self.on_error(err);
});

this.stream.on("close", function () {
Expand Down Expand Up @@ -148,19 +148,18 @@ RedisClient.prototype.flush_and_error = function (error) {
this.command_queue = new Queue();
};

RedisClient.prototype.on_error = function (msg) {
RedisClient.prototype.on_error = function (err) {
if (this.closing) {
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.ready = false;

this.emit("error", new Error(message));
this.emit("error", err);
// "error" events get turned into exceptions if they aren't listened for. If the user handled this error
// then we should try to reconnect.
this.connection_gone("error");
Expand Down Expand Up @@ -346,7 +345,8 @@ RedisClient.prototype.on_info_cmd = function (err, res) {
var line, retry_time, parts, sub_parts;

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++) {
Expand Down
14 changes: 13 additions & 1 deletion test/node_redis.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,12 @@ describe("The node_redis client", function () {
assert(i, 3);
assert.strictEqual(client.offline_queue.length, 0);
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);
}
});

Expand All @@ -785,7 +791,7 @@ describe("The node_redis client", 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, {
parser: parser,
max_attempts: 0,
Expand Down Expand Up @@ -840,6 +846,12 @@ describe("The node_redis client", function () {
if (/Redis connection in broken state:/.test(err.message)) {
assert.equal(client.command_queue.length, 0);
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);
}
});
});
Expand Down

0 comments on commit 1f121fa

Please sign in to comment.