From 52db91c7530cbca333fb47a9f8d2019856f15b63 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 2 Sep 2015 00:43:08 +0200 Subject: [PATCH 1/3] Fix js parser sending non-Errors --- index.js | 10 ++++------ lib/parser/javascript.js | 3 +-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index b87850b9ea..dffdbbb9e2 100644 --- a/index.js +++ b/index.js @@ -302,11 +302,7 @@ RedisClient.prototype.init_parser = function () { // "reply error" is an error sent back by Redis this.reply_parser.on("reply error", function (reply) { - if (reply instanceof Error) { - self.return_error(reply); - } else { - self.return_error(new Error(reply)); - } + self.return_error(reply); }); this.reply_parser.on("reply", function (reply) { self.return_reply(reply); @@ -654,7 +650,9 @@ RedisClient.prototype.return_reply = function (reply) { } try_callback(command_obj.callback, reply); - } else debug("no callback for reply: " + (reply && reply.toString && reply.toString())); + } else { + debug("no callback for reply: " + (reply && reply.toString && reply.toString())); + } } else if (this.pub_sub_mode || (command_obj && command_obj.sub_command)) { if (Array.isArray(reply)) { type = reply[0].toString(); diff --git a/lib/parser/javascript.js b/lib/parser/javascript.js index 15f8390900..bea4b68d9b 100644 --- a/lib/parser/javascript.js +++ b/lib/parser/javascript.js @@ -177,8 +177,7 @@ ReplyParser.prototype.execute = function (buffer) { if (ret === null) { break; } - - this.send_error(ret); + this.send_error(new Error(ret)); } else if (type === 58) { // : ret = this._parseResult(type); From 19db6d1dadca0539cf2d2b1cd3038b313ddce46d Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 2 Sep 2015 00:43:58 +0200 Subject: [PATCH 2/3] Remove lib/util.js --- index.js | 2 +- lib/parser/hiredis.js | 2 +- lib/parser/javascript.js | 2 +- lib/util.js | 13 ------------- 4 files changed, 3 insertions(+), 16 deletions(-) delete mode 100644 lib/util.js diff --git a/index.js b/index.js index dffdbbb9e2..11e6a77cb2 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ var net = require("net"), URL = require("url"), - util = require("./lib/util"), + util = require("util"), Queue = require("./lib/queue"), to_array = require("./lib/to_array"), events = require("events"), diff --git a/lib/parser/hiredis.js b/lib/parser/hiredis.js index f588bcc185..d1fd0b7a9a 100644 --- a/lib/parser/hiredis.js +++ b/lib/parser/hiredis.js @@ -1,7 +1,7 @@ 'use strict'; var events = require("events"), - util = require("../util"), + util = require("util"), hiredis = require("hiredis"); exports.name = "hiredis"; diff --git a/lib/parser/javascript.js b/lib/parser/javascript.js index bea4b68d9b..be5248d115 100644 --- a/lib/parser/javascript.js +++ b/lib/parser/javascript.js @@ -1,7 +1,7 @@ 'use strict'; var events = require("events"), - util = require("../util"); + util = require("util"); function Packet(type, size) { this.type = type; diff --git a/lib/util.js b/lib/util.js deleted file mode 100644 index 359cd7e948..0000000000 --- a/lib/util.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -// Support for very old versions of node where the module was called "sys". At some point, we should abandon this. - -var util; - -try { - util = require("util"); -} catch (err) { - util = require("sys"); -} - -module.exports = util; From 62041c519f33b3d0edfa7655ddb9f3b6190a0f31 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 2 Sep 2015 00:44:17 +0200 Subject: [PATCH 3/3] Test for statements instead of matching them if test is enough precompile regex --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 11e6a77cb2..50da18c91a 100644 --- a/index.js +++ b/index.js @@ -199,6 +199,9 @@ RedisClient.prototype.on_error = function (msg) { this.connection_gone("error"); }; +var noPasswordIsSet = /no password is set/; +var loading = /LOADING/; + RedisClient.prototype.do_auth = function () { var self = this; @@ -207,14 +210,14 @@ RedisClient.prototype.do_auth = function () { self.send_anyway = true; self.send_command("auth", [this.auth_pass], function (err, res) { if (err) { - if (err.toString().match("LOADING")) { + if (loading.test(err.message)) { // if redis is still loading the db, it will not authenticate and everything else will fail console.log("Redis still loading, trying to authenticate later"); setTimeout(function () { self.do_auth(); }, 2000); // TODO - magic number alert return; - } else if (err.toString().match("no password is set")) { + } else if (noPasswordIsSet.test(err.message)) { console.log("Warning: Redis server does not require a password, but a password was supplied."); err = null; res = "OK";