refactor(error): improve organization of Error kinds
				
					
				
			- Placed all cases of "unexpected bytes" errors into the `UnexpectedMessage` variant. - Placed all cases of "unexpected EOF" errors into the `IncompleteMessage` variant. Description is now generic about "connection closed before message completed", instead of mentioning "request" or "response. - Added `Error::is_incomplete_message()` accessor to help checking for unexpected closures. - Renamed some variants to be clearer when viewing the `Debug` format. - Collected all "user" errors into an internal `User` enum, to prevent forgetting to update the `is_user()` method.
This commit is contained in:
		| @@ -235,7 +235,7 @@ where | ||||
|             }, | ||||
|             Err(_req) => { | ||||
|                 debug!("connection was not ready"); | ||||
|                 let err = ::Error::new_canceled(Some("connection was not ready")); | ||||
|                 let err = ::Error::new_canceled().with("connection was not ready"); | ||||
|                 Either::B(future::err(err)) | ||||
|             } | ||||
|         }; | ||||
| @@ -262,7 +262,7 @@ where | ||||
|             }, | ||||
|             Err(req) => { | ||||
|                 debug!("connection was not ready"); | ||||
|                 let err = ::Error::new_canceled(Some("connection was not ready")); | ||||
|                 let err = ::Error::new_canceled().with("connection was not ready"); | ||||
|                 Either::B(future::err((err, Some(req)))) | ||||
|             } | ||||
|         } | ||||
| @@ -322,7 +322,7 @@ where | ||||
|             }, | ||||
|             Err(req) => { | ||||
|                 debug!("connection was not ready"); | ||||
|                 let err = ::Error::new_canceled(Some("connection was not ready")); | ||||
|                 let err = ::Error::new_canceled().with("connection was not ready"); | ||||
|                 Either::B(future::err((err, Some(req)))) | ||||
|             } | ||||
|         } | ||||
|   | ||||
| @@ -167,7 +167,7 @@ struct Envelope<T, U>(Option<(T, Callback<T, U>)>); | ||||
| impl<T, U> Drop for Envelope<T, U> { | ||||
|     fn drop(&mut self) { | ||||
|         if let Some((val, cb)) = self.0.take() { | ||||
|             let _ = cb.send(Err((::Error::new_canceled(None::<::Error>), Some(val)))); | ||||
|             let _ = cb.send(Err((::Error::new_canceled().with("connection closed"), Some(val)))); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -498,7 +498,7 @@ where C: Connect + Sync + 'static, | ||||
|             let connecting = match pool.connecting(&pool_key, ver) { | ||||
|                 Some(lock) => lock, | ||||
|                 None => { | ||||
|                     let canceled = ::Error::new_canceled(Some("HTTP/2 connection in progress")); | ||||
|                     let canceled = ::Error::new_canceled().with("HTTP/2 connection in progress"); | ||||
|                     return Either::B(future::err(canceled)); | ||||
|                 } | ||||
|             }; | ||||
| @@ -517,7 +517,7 @@ where C: Connect + Sync + 'static, | ||||
|                             None => { | ||||
|                                 // Another connection has already upgraded, | ||||
|                                 // the pool checkout should finish up for us. | ||||
|                                 let canceled = ::Error::new_canceled(Some("ALPN upgraded to HTTP/2")); | ||||
|                                 let canceled = ::Error::new_canceled().with("ALPN upgraded to HTTP/2"); | ||||
|                                 return Either::B(future::err(canceled)); | ||||
|                             } | ||||
|                         } | ||||
|   | ||||
| @@ -577,14 +577,14 @@ impl<T: Poolable> Checkout<T> { | ||||
|                     if value.is_open() { | ||||
|                         Ok(Async::Ready(Some(self.pool.reuse(&self.key, value)))) | ||||
|                     } else { | ||||
|                         Err(::Error::new_canceled(Some(CANCELED))) | ||||
|                         Err(::Error::new_canceled().with(CANCELED)) | ||||
|                     } | ||||
|                 }, | ||||
|                 Ok(Async::NotReady) => { | ||||
|                     self.waiter = Some(rx); | ||||
|                     Ok(Async::NotReady) | ||||
|                 }, | ||||
|                 Err(_canceled) => Err(::Error::new_canceled(Some(CANCELED))), | ||||
|                 Err(_canceled) => Err(::Error::new_canceled().with(CANCELED)), | ||||
|             } | ||||
|         } else { | ||||
|             Ok(Async::Ready(None)) | ||||
| @@ -654,7 +654,7 @@ impl<T: Poolable> Future for Checkout<T> { | ||||
|         if let Some(pooled) = self.checkout() { | ||||
|             Ok(Async::Ready(pooled)) | ||||
|         } else if !self.pool.is_enabled() { | ||||
|             Err(::Error::new_canceled(Some("pool is disabled"))) | ||||
|             Err(::Error::new_canceled().with("pool is disabled")) | ||||
|         } else { | ||||
|             Ok(Async::NotReady) | ||||
|         } | ||||
|   | ||||
| @@ -103,10 +103,7 @@ fn conn_reset_after_write() { | ||||
|         Ok(Async::Ready(())) | ||||
|     }).map_err(|e: ::std::io::Error| panic!("srv2 poll_fn error: {}", e)); | ||||
|     let err = rt.block_on(res2.join(srv2)).expect_err("res2"); | ||||
|     match err.kind() { | ||||
|         &::error::Kind::Incomplete => (), | ||||
|         other => panic!("expected Incomplete, found {:?}", other) | ||||
|     } | ||||
|     assert!(err.is_incomplete_message(), "{:?}", err); | ||||
| } | ||||
|  | ||||
| #[test] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user