Skip to content

Commit 38265d5

Browse files
committed
Merge pull request #809 from fintura/stuff
Remove some old stuff that is not needed anymore and fix js parser sending non-Errors as errors.
2 parents 614366f + 62041c5 commit 38265d5

File tree

4 files changed

+13
-26
lines changed

4 files changed

+13
-26
lines changed

index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
var net = require("net"),
66
URL = require("url"),
7-
util = require("./lib/util"),
7+
util = require("util"),
88
Queue = require("./lib/queue"),
99
to_array = require("./lib/to_array"),
1010
events = require("events"),
@@ -199,6 +199,9 @@ RedisClient.prototype.on_error = function (msg) {
199199
this.connection_gone("error");
200200
};
201201

202+
var noPasswordIsSet = /no password is set/;
203+
var loading = /LOADING/;
204+
202205
RedisClient.prototype.do_auth = function () {
203206
var self = this;
204207

@@ -207,14 +210,14 @@ RedisClient.prototype.do_auth = function () {
207210
self.send_anyway = true;
208211
self.send_command("auth", [this.auth_pass], function (err, res) {
209212
if (err) {
210-
if (err.toString().match("LOADING")) {
213+
if (loading.test(err.message)) {
211214
// if redis is still loading the db, it will not authenticate and everything else will fail
212215
console.log("Redis still loading, trying to authenticate later");
213216
setTimeout(function () {
214217
self.do_auth();
215218
}, 2000); // TODO - magic number alert
216219
return;
217-
} else if (err.toString().match("no password is set")) {
220+
} else if (noPasswordIsSet.test(err.message)) {
218221
console.log("Warning: Redis server does not require a password, but a password was supplied.");
219222
err = null;
220223
res = "OK";
@@ -302,11 +305,7 @@ RedisClient.prototype.init_parser = function () {
302305

303306
// "reply error" is an error sent back by Redis
304307
this.reply_parser.on("reply error", function (reply) {
305-
if (reply instanceof Error) {
306-
self.return_error(reply);
307-
} else {
308-
self.return_error(new Error(reply));
309-
}
308+
self.return_error(reply);
310309
});
311310
this.reply_parser.on("reply", function (reply) {
312311
self.return_reply(reply);
@@ -654,7 +653,9 @@ RedisClient.prototype.return_reply = function (reply) {
654653
}
655654

656655
try_callback(command_obj.callback, reply);
657-
} else debug("no callback for reply: " + (reply && reply.toString && reply.toString()));
656+
} else {
657+
debug("no callback for reply: " + (reply && reply.toString && reply.toString()));
658+
}
658659
} else if (this.pub_sub_mode || (command_obj && command_obj.sub_command)) {
659660
if (Array.isArray(reply)) {
660661
type = reply[0].toString();

lib/parser/hiredis.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
var events = require("events"),
4-
util = require("../util"),
4+
util = require("util"),
55
hiredis = require("hiredis");
66

77
exports.name = "hiredis";

lib/parser/javascript.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
var events = require("events"),
4-
util = require("../util");
4+
util = require("util");
55

66
function Packet(type, size) {
77
this.type = type;
@@ -177,8 +177,7 @@ ReplyParser.prototype.execute = function (buffer) {
177177
if (ret === null) {
178178
break;
179179
}
180-
181-
this.send_error(ret);
180+
this.send_error(new Error(ret));
182181
} else if (type === 58) { // :
183182
ret = this._parseResult(type);
184183

lib/util.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)