@@ -503,8 +503,11 @@ RedisClient.prototype.connection_gone = function (why) {
503503var err_code = / ^ ( [ A - Z ] + ) \s + ( .+ ) $ / ;
504504RedisClient . prototype . return_error = function ( err ) {
505505 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
506507 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 ;
508511 }
509512
510513 var match = err . message . match ( err_code ) ;
@@ -652,7 +655,9 @@ RedisClient.prototype.return_reply = function (reply) {
652655 } ) ;
653656 this . emit ( "monitor" , timestamp , args ) ;
654657 } 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 ) ;
656661 }
657662} ;
658663
@@ -706,7 +711,7 @@ RedisClient.prototype.send_command = function (command, args, callback) {
706711 if ( args [ args . length - 1 ] === undefined || args [ args . length - 1 ] === null ) {
707712 command = command . toUpperCase ( ) ;
708713 err = new Error ( 'send_command: ' + command + ' value must not be undefined or null' ) ;
709- err . command_used = command ;
714+ err . command = command ;
710715 if ( callback ) {
711716 return callback && callback ( err ) ;
712717 }
@@ -733,7 +738,7 @@ RedisClient.prototype.send_command = function (command, args, callback) {
733738 } else {
734739 err = new Error ( command + ' can\'t be processed. The connection has already been closed.' ) ;
735740 }
736- err . command_used = command ;
741+ err . command = command ;
737742 if ( callback ) {
738743 callback ( err ) ;
739744 } else {
@@ -754,7 +759,9 @@ RedisClient.prototype.send_command = function (command, args, callback) {
754759 } else if ( command === "quit" ) {
755760 this . closing = true ;
756761 } 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 ) ;
758765 return ;
759766 }
760767 this . command_queue . push ( command_obj ) ;
@@ -935,7 +942,7 @@ RedisClient.prototype.select = RedisClient.prototype.SELECT = function (db, call
935942RedisClient . prototype . auth = RedisClient . prototype . AUTH = function ( pass , callback ) {
936943 if ( typeof pass !== 'string' ) {
937944 var err = new Error ( 'The password has to be of type "string"' ) ;
938- err . command_used = 'AUTH' ;
945+ err . command = 'AUTH' ;
939946 if ( callback ) {
940947 callback ( err ) ;
941948 } else {
@@ -1056,7 +1063,7 @@ Multi.prototype.exec = Multi.prototype.EXEC = function (callback) {
10561063} ;
10571064
10581065Multi . prototype . execute_callback = function ( err , replies ) {
1059- var i , reply , args ;
1066+ var i , args ;
10601067
10611068 if ( err ) {
10621069 if ( err . code !== 'CONNECTION_BROKEN' ) {
@@ -1072,32 +1079,32 @@ Multi.prototype.execute_callback = function (err, replies) {
10721079 }
10731080
10741081 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 ] ;
10781084
10791085 // 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 ) ;
10821088 // LUA script could return user errors that don't behave like all other errors!
10831089 if ( match ) {
1084- reply . code = match [ 1 ] ;
1090+ replies [ i ] . code = match [ 1 ] ;
10851091 }
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 ] ) ;
10891096 }
10901097 if ( args [ 0 ] === "hgetall" ) {
10911098 // 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 ] ) ;
10931100 }
10941101 }
10951102
10961103 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 ] ) ;
10991106 } else {
1100- args [ args . length - 1 ] ( null , reply ) ;
1107+ args [ args . length - 1 ] ( null , replies [ i ] ) ;
11011108 }
11021109 }
11031110 }
0 commit comments