Skip to content

Commit 40c037e

Browse files
author
Ruben Bridgewater
committed
Add redis error codes to the errors
1 parent 7e68925 commit 40c037e

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,19 @@ RedisClient.prototype.connection_gone = function (why) {
500500
this.retry_timer = setTimeout(retry_connection, this.retry_delay, this);
501501
};
502502

503+
var err_code = /^([A-Z]+)\s+(.+)$/;
503504
RedisClient.prototype.return_error = function (err) {
504505
var command_obj = this.command_queue.shift(), queue_len = this.command_queue.length;
505506
if (command_obj.command && command_obj.command.toUpperCase) {
506507
err.command_used = command_obj.command.toUpperCase();
507508
}
508509

510+
var match = err.message.match(err_code);
511+
// LUA script could return user errors that don't behave like all other errors!
512+
if (match) {
513+
err.code = match[1];
514+
}
515+
509516
if (this.pub_sub_mode === false && queue_len === 0) {
510517
this.command_queue = new Queue();
511518
this.emit("idle");

test/commands/eval.spec.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ describe("The 'eval' method", function () {
5252

5353
it('converts lua error to an error response', function (done) {
5454
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
55-
client.eval("return {err='this is an error'}", 0, helper.isError(done));
55+
client.eval("return {err='this is an error'}", 0, function(err) {
56+
assert(err.code === undefined);
57+
helper.isError()(err);
58+
done();
59+
});
5660
});
5761

5862
it('represents a lua table appropritely', function (done) {

test/commands/keys.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ describe("The 'keys' method", function () {
1414
var client;
1515

1616
beforeEach(function (done) {
17+
args = args || {};
18+
// This is going to test if the high water is also respected
19+
args.command_queue_high_water = 100;
1720
client = redis.createClient.apply(redis.createClient, args);
1821
client.once("connect", function () {
1922
client.flushdb(done);

0 commit comments

Comments
 (0)