@@ -503,8 +503,11 @@ RedisClient.prototype.connection_gone = function (why) {
503
503
var err_code = / ^ ( [ A - Z ] + ) \s + ( .+ ) $ / ;
504
504
RedisClient . prototype . return_error = function ( err ) {
505
505
var command_obj = this . command_queue . shift ( ) , queue_len = this . command_queue . length ;
506
+ // send_command might have been used wrong => catch those cases too
506
507
if ( command_obj . command && command_obj . command . toUpperCase ) {
507
- err . command_used = command_obj . command . toUpperCase ( ) ;
508
+ err . command = command_obj . command . toUpperCase ( ) ;
509
+ } else {
510
+ err . command = command_obj . command ;
508
511
}
509
512
510
513
var match = err . message . match ( err_code ) ;
@@ -652,7 +655,9 @@ RedisClient.prototype.return_reply = function (reply) {
652
655
} ) ;
653
656
this . emit ( "monitor" , timestamp , args ) ;
654
657
} else {
655
- this . emit ( "error" , new Error ( "node_redis command queue state error. If you can reproduce this, please report it." ) ) ;
658
+ var err = new Error ( "node_redis command queue state error. If you can reproduce this, please report it." ) ;
659
+ err . command = command_obj . command . toUpperCase ( ) ;
660
+ this . emit ( "error" , err ) ;
656
661
}
657
662
} ;
658
663
@@ -706,7 +711,7 @@ RedisClient.prototype.send_command = function (command, args, callback) {
706
711
if ( args [ args . length - 1 ] === undefined || args [ args . length - 1 ] === null ) {
707
712
command = command . toUpperCase ( ) ;
708
713
err = new Error ( 'send_command: ' + command + ' value must not be undefined or null' ) ;
709
- err . command_used = command ;
714
+ err . command = command ;
710
715
if ( callback ) {
711
716
return callback && callback ( err ) ;
712
717
}
@@ -733,7 +738,7 @@ RedisClient.prototype.send_command = function (command, args, callback) {
733
738
} else {
734
739
err = new Error ( command + ' can\'t be processed. The connection has already been closed.' ) ;
735
740
}
736
- err . command_used = command ;
741
+ err . command = command ;
737
742
if ( callback ) {
738
743
callback ( err ) ;
739
744
} else {
@@ -754,7 +759,9 @@ RedisClient.prototype.send_command = function (command, args, callback) {
754
759
} else if ( command === "quit" ) {
755
760
this . closing = true ;
756
761
} else if ( this . pub_sub_mode === true ) {
757
- this . emit ( "error" , new Error ( "Connection in subscriber mode, only subscriber commands may be used" ) ) ;
762
+ err = new Error ( "Connection in subscriber mode, only subscriber commands may be used" ) ;
763
+ err . command = command . toUpperCase ( ) ;
764
+ this . emit ( "error" , err ) ;
758
765
return ;
759
766
}
760
767
this . command_queue . push ( command_obj ) ;
@@ -935,7 +942,7 @@ RedisClient.prototype.select = RedisClient.prototype.SELECT = function (db, call
935
942
RedisClient . prototype . auth = RedisClient . prototype . AUTH = function ( pass , callback ) {
936
943
if ( typeof pass !== 'string' ) {
937
944
var err = new Error ( 'The password has to be of type "string"' ) ;
938
- err . command_used = 'AUTH' ;
945
+ err . command = 'AUTH' ;
939
946
if ( callback ) {
940
947
callback ( err ) ;
941
948
} else {
@@ -1056,7 +1063,7 @@ Multi.prototype.exec = Multi.prototype.EXEC = function (callback) {
1056
1063
} ;
1057
1064
1058
1065
Multi . prototype . execute_callback = function ( err , replies ) {
1059
- var i , reply , args ;
1066
+ var i , args ;
1060
1067
1061
1068
if ( err ) {
1062
1069
if ( err . code !== 'CONNECTION_BROKEN' ) {
@@ -1072,32 +1079,32 @@ Multi.prototype.execute_callback = function (err, replies) {
1072
1079
}
1073
1080
1074
1081
if ( replies ) {
1075
- for ( i = 1 ; i < this . queue . length ; i += 1 ) {
1076
- reply = replies [ i - 1 ] ;
1077
- args = this . queue [ i ] ;
1082
+ for ( i = 0 ; i < this . queue . length - 1 ; i += 1 ) {
1083
+ args = this . queue [ i + 1 ] ;
1078
1084
1079
1085
// If we asked for strings, even in detect_buffers mode, then return strings:
1080
- if ( reply instanceof Error ) {
1081
- var match = reply . message . match ( err_code ) ;
1086
+ if ( replies [ i ] instanceof Error ) {
1087
+ var match = replies [ i ] . message . match ( err_code ) ;
1082
1088
// LUA script could return user errors that don't behave like all other errors!
1083
1089
if ( match ) {
1084
- reply . code = match [ 1 ] ;
1090
+ replies [ i ] . code = match [ 1 ] ;
1085
1091
}
1086
- } else if ( reply ) {
1087
- if ( this . _client . options . detect_buffers && this . wants_buffers [ i ] === false ) {
1088
- replies [ i - 1 ] = reply = reply_to_strings ( reply ) ;
1092
+ replies [ i ] . command = args [ 0 ] . toUpperCase ( ) ;
1093
+ } else if ( replies [ i ] ) {
1094
+ if ( this . _client . options . detect_buffers && this . wants_buffers [ i + 1 ] === false ) {
1095
+ replies [ i ] = reply_to_strings ( replies [ i ] ) ;
1089
1096
}
1090
1097
if ( args [ 0 ] === "hgetall" ) {
1091
1098
// TODO - confusing and error-prone that hgetall is special cased in two places
1092
- replies [ i - 1 ] = reply = reply_to_object ( reply ) ;
1099
+ replies [ i ] = reply_to_object ( replies [ i ] ) ;
1093
1100
}
1094
1101
}
1095
1102
1096
1103
if ( typeof args [ args . length - 1 ] === "function" ) {
1097
- if ( reply instanceof Error ) {
1098
- args [ args . length - 1 ] ( reply ) ;
1104
+ if ( replies [ i ] instanceof Error ) {
1105
+ args [ args . length - 1 ] ( replies [ i ] ) ;
1099
1106
} else {
1100
- args [ args . length - 1 ] ( null , reply ) ;
1107
+ args [ args . length - 1 ] ( null , replies [ i ] ) ;
1101
1108
}
1102
1109
}
1103
1110
}
0 commit comments