@@ -147,9 +147,7 @@ RedisClient.prototype.flush_and_error = function (message) {
147
147
try {
148
148
command_obj . callback ( error ) ;
149
149
} catch ( callback_err ) {
150
- process . nextTick ( function ( ) {
151
- throw callback_err ;
152
- } ) ;
150
+ this . emit ( "error" , callback_err ) ;
153
151
}
154
152
}
155
153
}
@@ -161,9 +159,7 @@ RedisClient.prototype.flush_and_error = function (message) {
161
159
try {
162
160
command_obj . callback ( error ) ;
163
161
} catch ( callback_err ) {
164
- process . nextTick ( function ( ) {
165
- throw callback_err ;
166
- } ) ;
162
+ this . emit ( "error" , callback_err ) ;
167
163
}
168
164
}
169
165
}
@@ -559,34 +555,26 @@ RedisClient.prototype.return_error = function (err) {
559
555
try {
560
556
command_obj . callback ( err ) ;
561
557
} catch ( callback_err ) {
562
- // if a callback throws an exception, re-throw it on a new stack so the parser can keep going
563
- process . nextTick ( function ( ) {
564
- throw callback_err ;
565
- } ) ;
558
+ this . emit ( "error" , callback_err ) ;
566
559
}
567
560
} else {
568
561
console . log ( "node_redis: no callback to send error: " + err . message ) ;
569
- // this will probably not make it anywhere useful, but we might as well throw
570
- process . nextTick ( function ( ) {
571
- throw err ;
572
- } ) ;
562
+ this . emit ( "error" , err ) ;
573
563
}
574
564
} ;
575
565
576
566
// if a callback throws an exception, re-throw it on a new stack so the parser can keep going.
577
567
// if a domain is active, emit the error on the domain, which will serve the same function.
578
568
// put this try/catch in its own function because V8 doesn't optimize this well yet.
579
- function try_callback ( callback , reply ) {
569
+ function try_callback ( client , callback , reply ) {
580
570
try {
581
571
callback ( null , reply ) ;
582
572
} catch ( err ) {
583
573
if ( process . domain ) {
584
574
process . domain . emit ( 'error' , err ) ;
585
575
process . domain . exit ( ) ;
586
576
} else {
587
- process . nextTick ( function ( ) {
588
- throw err ;
589
- } ) ;
577
+ client . emit ( "error" , err ) ;
590
578
}
591
579
}
592
580
}
@@ -668,7 +656,7 @@ RedisClient.prototype.return_reply = function (reply) {
668
656
reply = reply_to_object ( reply ) ;
669
657
}
670
658
671
- try_callback ( command_obj . callback , reply ) ;
659
+ try_callback ( this , command_obj . callback , reply ) ;
672
660
} else if ( exports . debug_mode ) {
673
661
console . log ( "no callback for reply: " + ( reply && reply . toString && reply . toString ( ) ) ) ;
674
662
}
@@ -694,7 +682,7 @@ RedisClient.prototype.return_reply = function (reply) {
694
682
// reply[1] can be null
695
683
var reply1String = ( reply [ 1 ] === null ) ? null : reply [ 1 ] . toString ( ) ;
696
684
if ( command_obj && typeof command_obj . callback === "function" ) {
697
- try_callback ( command_obj . callback , reply1String ) ;
685
+ try_callback ( this , command_obj . callback , reply1String ) ;
698
686
}
699
687
this . emit ( type , reply1String , reply [ 2 ] ) ; // channel, count
700
688
} else {
0 commit comments