@@ -152,27 +152,15 @@ RedisClient.prototype.flush_and_error = function (message) {
152
152
while ( this . offline_queue . length > 0 ) {
153
153
command_obj = this . offline_queue . shift ( ) ;
154
154
if ( typeof command_obj . callback === "function" ) {
155
- try {
156
- command_obj . callback ( error ) ;
157
- } catch ( callback_err ) {
158
- process . nextTick ( function ( ) {
159
- throw callback_err ;
160
- } ) ;
161
- }
155
+ command_obj . callback ( error ) ;
162
156
}
163
157
}
164
158
this . offline_queue = new Queue ( ) ;
165
159
166
160
while ( this . command_queue . length > 0 ) {
167
161
command_obj = this . command_queue . shift ( ) ;
168
162
if ( typeof command_obj . callback === "function" ) {
169
- try {
170
- command_obj . callback ( error ) ;
171
- } catch ( callback_err ) {
172
- process . nextTick ( function ( ) {
173
- throw callback_err ;
174
- } ) ;
175
- }
163
+ command_obj . callback ( error ) ;
176
164
}
177
165
}
178
166
this . command_queue = new Queue ( ) ;
@@ -292,6 +280,8 @@ RedisClient.prototype.init_parser = function () {
292
280
return true ;
293
281
}
294
282
} ) ) {
283
+ // Do not emit this error
284
+ // This should take down the app if anyone made such a huge mistake or should somehow be handled in user code
295
285
throw new Error ( "Couldn't find named parser " + self . options . parser + " on this system" ) ;
296
286
}
297
287
} else {
@@ -529,38 +519,13 @@ RedisClient.prototype.return_error = function (err) {
529
519
this . emit ( "drain" ) ;
530
520
this . should_buffer = false ;
531
521
}
532
-
533
- try {
522
+ if ( command_obj . callback ) {
534
523
command_obj . callback ( err ) ;
535
- } catch ( callback_err ) {
536
- // if a callback throws an exception, re-throw it on a new stack so the parser can keep going
537
- process . nextTick ( function ( ) {
538
- throw callback_err ;
539
- } ) ;
524
+ } else {
525
+ this . emit ( 'error' , err ) ;
540
526
}
541
527
} ;
542
528
543
- // if a callback throws an exception, re-throw it on a new stack so the parser can keep going.
544
- // if a domain is active, emit the error on the domain, which will serve the same function.
545
- // put this try/catch in its own function because V8 doesn't optimize this well yet.
546
- function try_callback ( callback , reply ) {
547
- try {
548
- callback ( null , reply ) ;
549
- } catch ( err ) {
550
- if ( process . domain ) {
551
- var currDomain = process . domain ;
552
- currDomain . emit ( 'error' , err ) ;
553
- if ( process . domain === currDomain ) {
554
- currDomain . exit ( ) ;
555
- }
556
- } else {
557
- process . nextTick ( function ( ) {
558
- throw err ;
559
- } ) ;
560
- }
561
- }
562
- }
563
-
564
529
// hgetall converts its replies to an Object. If the reply is empty, null is returned.
565
530
function reply_to_object ( reply ) {
566
531
var obj = { } , j , jl , key , val ;
@@ -638,7 +603,7 @@ RedisClient.prototype.return_reply = function (reply) {
638
603
reply = reply_to_object ( reply ) ;
639
604
}
640
605
641
- try_callback ( command_obj . callback , reply ) ;
606
+ command_obj . callback ( null , reply ) ;
642
607
} else {
643
608
debug ( "no callback for reply: " + ( reply && reply . toString && reply . toString ( ) ) ) ;
644
609
}
@@ -662,14 +627,16 @@ RedisClient.prototype.return_reply = function (reply) {
662
627
// reply[1] can be null
663
628
var reply1String = ( reply [ 1 ] === null ) ? null : reply [ 1 ] . toString ( ) ;
664
629
if ( command_obj && typeof command_obj . callback === "function" ) {
665
- try_callback ( command_obj . callback , reply1String ) ;
630
+ command_obj . callback ( null , reply1String ) ;
666
631
}
667
632
this . emit ( type , reply1String , reply [ 2 ] ) ; // channel, count
668
633
} else {
669
- throw new Error ( "subscriptions are active but got unknown reply type " + type ) ;
634
+ this . emit ( "error" , new Error ( "subscriptions are active but got unknown reply type " + type ) ) ;
635
+ return ;
670
636
}
671
- } else if ( ! this . closing ) {
672
- throw new Error ( "subscriptions are active but got an invalid reply: " + reply ) ;
637
+ } else if ( ! this . closing ) {
638
+ this . emit ( "error" , new Error ( "subscriptions are active but got an invalid reply: " + reply ) ) ;
639
+ return ;
673
640
}
674
641
} else if ( this . monitoring ) {
675
642
len = reply . indexOf ( " " ) ;
@@ -680,7 +647,7 @@ RedisClient.prototype.return_reply = function (reply) {
680
647
} ) ;
681
648
this . emit ( "monitor" , timestamp , args ) ;
682
649
} else {
683
- throw new Error ( "node_redis command queue state error. If you can reproduce this, please report it." ) ;
650
+ this . emit ( "error" , new Error ( "node_redis command queue state error. If you can reproduce this, please report it." ) ) ;
684
651
}
685
652
} ;
686
653
@@ -739,9 +706,16 @@ RedisClient.prototype.send_command = function (command, args, callback) {
739
706
740
707
// if the value is undefined or null and command is set or setx, need not to send message to redis
741
708
if ( command === 'set' || command === 'setex' ) {
742
- if ( args [ args . length - 1 ] === undefined || args [ args . length - 1 ] === null ) {
709
+ if ( args . length === 0 ) {
710
+ return ;
711
+ }
712
+ if ( args [ args . length - 1 ] === undefined || args [ args . length - 1 ] === null ) {
743
713
var err = new Error ( 'send_command: ' + command + ' value must not be undefined or null' ) ;
744
- return callback && callback ( err ) ;
714
+ if ( callback ) {
715
+ return callback && callback ( err ) ;
716
+ }
717
+ this . emit ( "error" , err ) ;
718
+ return ;
745
719
}
746
720
}
747
721
@@ -768,7 +742,8 @@ RedisClient.prototype.send_command = function (command, args, callback) {
768
742
if ( command_obj . callback ) {
769
743
command_obj . callback ( not_writeable_error ) ;
770
744
} else {
771
- throw not_writeable_error ;
745
+ this . emit ( "error" , not_writeable_error ) ;
746
+ return ;
772
747
}
773
748
}
774
749
@@ -782,7 +757,8 @@ RedisClient.prototype.send_command = function (command, args, callback) {
782
757
} else if ( command === "quit" ) {
783
758
this . closing = true ;
784
759
} else if ( this . pub_sub_mode === true ) {
785
- throw new Error ( "Connection in subscriber mode, only subscriber commands may be used" ) ;
760
+ this . emit ( "error" , new Error ( "Connection in subscriber mode, only subscriber commands may be used" ) ) ;
761
+ return ;
786
762
}
787
763
this . command_queue . push ( command_obj ) ;
788
764
this . commands_sent += 1 ;
@@ -1069,7 +1045,7 @@ Multi.prototype.exec = function (callback) {
1069
1045
callback ( errors ) ;
1070
1046
return ;
1071
1047
} else {
1072
- throw new Error ( err ) ;
1048
+ self . _client . emit ( 'error' , err ) ;
1073
1049
}
1074
1050
}
1075
1051
0 commit comments