@@ -154,7 +154,9 @@ RedisClient.prototype.flush_and_error = function (message) {
154
154
try {
155
155
command_obj . callback ( error ) ;
156
156
} catch ( callback_err ) {
157
- this . emit ( "error" , callback_err ) ;
157
+ process . nextTick ( function ( ) {
158
+ throw callback_err ;
159
+ } ) ;
158
160
}
159
161
}
160
162
}
@@ -166,7 +168,9 @@ RedisClient.prototype.flush_and_error = function (message) {
166
168
try {
167
169
command_obj . callback ( error ) ;
168
170
} catch ( callback_err ) {
169
- this . emit ( "error" , callback_err ) ;
171
+ process . nextTick ( function ( ) {
172
+ throw callback_err ;
173
+ } ) ;
170
174
}
171
175
}
172
176
}
@@ -566,18 +570,24 @@ RedisClient.prototype.return_error = function (err) {
566
570
try {
567
571
command_obj . callback ( err ) ;
568
572
} catch ( callback_err ) {
569
- this . emit ( "error" , callback_err ) ;
573
+ // if a callback throws an exception, re-throw it on a new stack so the parser can keep going
574
+ process . nextTick ( function ( ) {
575
+ throw callback_err ;
576
+ } ) ;
570
577
}
571
578
} else {
572
579
console . log ( "node_redis: no callback to send error: " + err . message ) ;
573
- this . emit ( "error" , err ) ;
580
+ // this will probably not make it anywhere useful, but we might as well throw
581
+ process . nextTick ( function ( ) {
582
+ throw err ;
583
+ } ) ;
574
584
}
575
585
} ;
576
586
577
587
// if a callback throws an exception, re-throw it on a new stack so the parser can keep going.
578
588
// if a domain is active, emit the error on the domain, which will serve the same function.
579
589
// put this try/catch in its own function because V8 doesn't optimize this well yet.
580
- function try_callback ( client , callback , reply ) {
590
+ function try_callback ( callback , reply ) {
581
591
try {
582
592
callback ( null , reply ) ;
583
593
} catch ( err ) {
@@ -588,7 +598,9 @@ function try_callback(client, callback, reply) {
588
598
currDomain . exit ( ) ;
589
599
}
590
600
} else {
591
- client . emit ( "error" , err ) ;
601
+ process . nextTick ( function ( ) {
602
+ throw err ;
603
+ } ) ;
592
604
}
593
605
}
594
606
}
@@ -670,7 +682,7 @@ RedisClient.prototype.return_reply = function (reply) {
670
682
reply = reply_to_object ( reply ) ;
671
683
}
672
684
673
- try_callback ( this , command_obj . callback , reply ) ;
685
+ try_callback ( command_obj . callback , reply ) ;
674
686
} else if ( exports . debug_mode ) {
675
687
console . log ( "no callback for reply: " + ( reply && reply . toString && reply . toString ( ) ) ) ;
676
688
}
@@ -696,7 +708,7 @@ RedisClient.prototype.return_reply = function (reply) {
696
708
// reply[1] can be null
697
709
var reply1String = ( reply [ 1 ] === null ) ? null : reply [ 1 ] . toString ( ) ;
698
710
if ( command_obj && typeof command_obj . callback === "function" ) {
699
- try_callback ( this , command_obj . callback , reply1String ) ;
711
+ try_callback ( command_obj . callback , reply1String ) ;
700
712
}
701
713
this . emit ( type , reply1String , reply [ 2 ] ) ; // channel, count
702
714
} else {
0 commit comments