Skip to content

Commit 1a06cfb

Browse files
author
Ruben Bridgewater
committed
Add .command_used to errors thrown by the parser
1 parent e4bd9bf commit 1a06cfb

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ RedisClient.prototype.on_data = function (data) {
509509

510510
RedisClient.prototype.return_error = function (err) {
511511
var command_obj = this.command_queue.shift(), queue_len = this.command_queue.length;
512+
err.command_used = command_obj.command.toUpperCase();
512513

513514
if (this.pub_sub_mode === false && queue_len === 0) {
514515
this.command_queue = new Queue();

test/auth.spec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ describe("client authentication", function () {
3939

4040
client = redis.createClient.apply(redis.createClient, args);
4141

42-
client.once('error', function (error) {
43-
assert.ok(/ERR invalid password/.test(error));
42+
client.once('error', function (err) {
43+
assert.strictEqual(err.command_used, 'AUTH');
44+
assert.ok(/ERR invalid password/.test(err.message));
4445
return done();
4546
});
4647

test/commands/select.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ describe("The 'select' method", function () {
9494
assert.strictEqual(client.selected_db, null, "default db should be null");
9595

9696
client.on('error', function (err) {
97+
assert.strictEqual(err.command_used, 'SELECT');
9798
assert.equal(err.message, 'ERR invalid DB index');
9899
done();
99100
});

0 commit comments

Comments
 (0)