You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
Emit errors instead of throwing them
Thrown errors might kill the users app. By emitting the errors the user is able to catch all errors in one place without the app going down
This commit is contained in:
31
index.js
31
index.js
@@ -280,6 +280,8 @@ RedisClient.prototype.init_parser = function () {
|
||||
return true;
|
||||
}
|
||||
})) {
|
||||
// Do not emit this error
|
||||
// This should take down the app if anyone made such a huge mistake or should somehow be handled in user code
|
||||
throw new Error("Couldn't find named parser " + self.options.parser + " on this system");
|
||||
}
|
||||
} else {
|
||||
@@ -629,10 +631,12 @@ RedisClient.prototype.return_reply = function (reply) {
|
||||
}
|
||||
this.emit(type, reply1String, reply[2]); // channel, count
|
||||
} else {
|
||||
throw new Error("subscriptions are active but got unknown reply type " + type);
|
||||
this.emit("error", new Error("subscriptions are active but got unknown reply type " + type));
|
||||
return;
|
||||
}
|
||||
} else if (! this.closing) {
|
||||
throw new Error("subscriptions are active but got an invalid reply: " + reply);
|
||||
} else if (!this.closing) {
|
||||
this.emit("error", new Error("subscriptions are active but got an invalid reply: " + reply));
|
||||
return;
|
||||
}
|
||||
} else if (this.monitoring) {
|
||||
len = reply.indexOf(" ");
|
||||
@@ -643,7 +647,7 @@ RedisClient.prototype.return_reply = function (reply) {
|
||||
});
|
||||
this.emit("monitor", timestamp, args);
|
||||
} else {
|
||||
throw new Error("node_redis command queue state error. If you can reproduce this, please report it.");
|
||||
this.emit("error", new Error("node_redis command queue state error. If you can reproduce this, please report it."));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -702,9 +706,16 @@ RedisClient.prototype.send_command = function (command, args, callback) {
|
||||
|
||||
// if the value is undefined or null and command is set or setx, need not to send message to redis
|
||||
if (command === 'set' || command === 'setex') {
|
||||
if(args[args.length - 1] === undefined || args[args.length - 1] === null) {
|
||||
if (args.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (args[args.length - 1] === undefined || args[args.length - 1] === null) {
|
||||
var err = new Error('send_command: ' + command + ' value must not be undefined or null');
|
||||
return callback && callback(err);
|
||||
if (callback) {
|
||||
return callback && callback(err);
|
||||
}
|
||||
this.emit("error", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -731,7 +742,8 @@ RedisClient.prototype.send_command = function (command, args, callback) {
|
||||
if (command_obj.callback) {
|
||||
command_obj.callback(not_writeable_error);
|
||||
} else {
|
||||
throw not_writeable_error;
|
||||
this.emit("error", not_writeable_error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -745,7 +757,8 @@ RedisClient.prototype.send_command = function (command, args, callback) {
|
||||
} else if (command === "quit") {
|
||||
this.closing = true;
|
||||
} else if (this.pub_sub_mode === true) {
|
||||
throw new Error("Connection in subscriber mode, only subscriber commands may be used");
|
||||
this.emit("error", new Error("Connection in subscriber mode, only subscriber commands may be used"));
|
||||
return;
|
||||
}
|
||||
this.command_queue.push(command_obj);
|
||||
this.commands_sent += 1;
|
||||
@@ -1032,7 +1045,7 @@ Multi.prototype.exec = function (callback) {
|
||||
callback(errors);
|
||||
return;
|
||||
} else {
|
||||
throw new Error(err);
|
||||
self._client.emit('error', err);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user