@@ -227,21 +227,15 @@ impl WorkerJob {
227
227
payload. put_u8 ( b'\0' ) ;
228
228
payload. extend ( denominator. as_bytes ( ) ) ;
229
229
let packet = new_res ( WORK_STATUS , payload. freeze ( ) ) ;
230
- self . send_packet ( packet) . await . map_err ( |e| {
231
- if e. is :: < std:: io:: Error > ( ) {
232
- * e. downcast :: < std:: io:: Error > ( ) . expect ( "downcast after is" )
233
- } else {
234
- std:: io:: Error :: new ( io:: ErrorKind :: Other , e. to_string ( ) )
235
- }
236
- } )
230
+ self . send_packet ( packet) . await
237
231
}
238
232
239
- async fn send_packet ( & mut self , packet : Packet ) -> Result < ( ) , Box < dyn Error > > {
233
+ pub async fn send_packet ( & mut self , packet : Packet ) -> Result < ( ) , io :: Error > {
240
234
match self . sink_tx . send ( packet) . await {
241
- Err ( _) => Err ( Box :: new ( io:: Error :: new (
235
+ Err ( _) => Err ( io:: Error :: new (
242
236
io:: ErrorKind :: NotConnected ,
243
237
"Connection closed" ,
244
- ) ) ) ,
238
+ ) ) ,
245
239
Ok ( _) => Ok ( ( ) ) ,
246
240
}
247
241
}
@@ -250,7 +244,7 @@ impl WorkerJob {
250
244
///
251
245
/// This method is typically called by the [Client::work] method upon return
252
246
/// of an error from the assigned closure.
253
- pub async fn work_fail ( & mut self ) -> Result < ( ) , Box < dyn Error > > {
247
+ pub async fn work_fail ( & mut self ) -> Result < ( ) , io :: Error > {
254
248
let packet = new_res ( WORK_FAIL , self . handle . clone ( ) ) ;
255
249
self . send_packet ( packet) . await
256
250
}
@@ -259,7 +253,7 @@ impl WorkerJob {
259
253
///
260
254
/// This method is typically called by the [Client::work] method upon return of
261
255
/// the assigned closure.
262
- pub async fn work_complete ( & mut self , response : Vec < u8 > ) -> Result < ( ) , Box < dyn Error > > {
256
+ pub async fn work_complete ( & mut self , response : Vec < u8 > ) -> Result < ( ) , io :: Error > {
263
257
let mut payload = BytesMut :: with_capacity ( self . handle . len ( ) + 1 + self . payload . len ( ) ) ;
264
258
payload. extend ( self . handle . clone ( ) ) ;
265
259
payload. put_u8 ( b'\0' ) ;
@@ -449,29 +443,38 @@ impl Client {
449
443
let tx = tx. clone ( ) ;
450
444
while let Some ( frame) = stream. next ( ) . await {
451
445
trace ! ( "Frame read: {:?}" , frame) ;
452
- let response = match frame {
453
- Err ( e) => Err ( e. to_string ( ) ) ,
454
- Ok ( frame) => {
455
- let handler = handler. clone ( ) ;
456
- debug ! ( "Locking handler" ) ;
457
- let mut handler = handler;
458
- debug ! ( "Locked handler" ) ;
459
- handler
460
- . call ( frame)
461
- . map_err ( |e| e. to_string ( ) )
462
- }
463
- } ;
464
- match response {
465
- Err ( e) => {
466
- error ! ( "conn dropped?: {}" , e) ;
467
- break ;
468
- }
469
- Ok ( response) => {
470
- if let Err ( _) = tx. send ( response) . await
471
- {
472
- error ! ( "receiver dropped" )
446
+ // This lexical scope is needed because the compiler can't figure out
447
+ // that response's error is dropped before the await.
448
+ // See: https://github.com/rust-lang/rust/pull/107421 for the fix
449
+ // which is only in nightly as of this writing.
450
+ let packet = {
451
+ let response = match frame {
452
+ Err ( e) => {
453
+ Err ( Box :: new ( e) as Box < dyn Error > )
454
+ }
455
+ Ok ( frame) => {
456
+ let handler = handler. clone ( ) ;
457
+ debug ! ( "Locking handler" ) ;
458
+ let mut handler = handler;
459
+ debug ! ( "Locked handler" ) ;
460
+ handler. call ( frame)
461
+ } //.map_err(|e| e)
462
+ // Ugh this map_err
463
+ } ;
464
+ match response {
465
+ Err ( e) => {
466
+ if e. is :: < io:: Error > ( ) {
467
+ error ! ( "conn dropped?: {}" , e) ;
468
+ break ;
469
+ }
470
+ error ! ( "There was a non-fatal error while processing a packet: {}" , e) ;
471
+ continue ;
473
472
}
473
+ Ok ( packet) => packet,
474
474
}
475
+ } ;
476
+ if let Err ( _) = tx. send ( packet) . await {
477
+ warn ! ( "receiver dropped" )
475
478
}
476
479
}
477
480
reader_conns
0 commit comments