From 0f4055f9ecfaaa3b5bc4a153f3038b41f03086a8 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Thu, 3 Jan 2019 11:07:09 -0800 Subject: [PATCH] remove Error::is_runtime_startup accessor --- src/client.rs | 22 +++++++++++++--------- src/error.rs | 21 ++------------------- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/client.rs b/src/client.rs index 8235dfc..4dd0847 100644 --- a/src/client.rs +++ b/src/client.rs @@ -504,7 +504,7 @@ impl ClientHandle { match spawn_rx.wait() { Ok(Ok(())) => (), Ok(Err(err)) => return Err(err), - Err(_canceled) => return Err(::error::runtime_startup()), + Err(_canceled) => event_loop_panicked(), } @@ -537,14 +537,7 @@ impl ClientHandle { Either::B(future::ok(())) }; - let rx = rx.map_err(|_canceled| { - // The only possible reason there would be a Canceled error - // is if the thread running the event loop panicked. We could return - // an Err here, like a BrokenPipe, but the Client is not - // recoverable. Additionally, the panic in the other thread - // is not normal, and should likely be propagated. - panic!("event loop thread panicked"); - }); + let rx = rx.map_err(|_canceled| event_loop_panicked()); let fut = write.join(rx).map(|((), res)| res); @@ -578,3 +571,14 @@ impl KeepCoreThreadAlive { KeepCoreThreadAlive(None) } } + +#[cold] +#[inline(never)] +fn event_loop_panicked() -> ! { + // The only possible reason there would be a Canceled error + // is if the thread running the event loop panicked. We could return + // an Err here, like a BrokenPipe, but the Client is not + // recoverable. Additionally, the panic in the other thread + // is not normal, and should likely be propagated. + panic!("event loop thread panicked"); +} diff --git a/src/error.rs b/src/error.rs index 0ac7acb..88e2946 100644 --- a/src/error.rs +++ b/src/error.rs @@ -147,8 +147,7 @@ impl Error { Kind::TooManyRedirects | Kind::RedirectLoop | Kind::ClientError(_) | - Kind::ServerError(_) | - Kind::RuntimeStartupFailure => None, + Kind::ServerError(_) => None, } } @@ -209,14 +208,6 @@ impl Error { _ => None, } } - - /// Returns true if this error is due to a failure starting the runtime. - pub fn is_runtime_startup(&self) -> bool { - match self.inner.kind { - Kind::RuntimeStartupFailure => true, - _ => false, - } - } } impl fmt::Debug for Error { @@ -259,7 +250,6 @@ impl fmt::Display for Error { f.write_str("Server Error: ")?; fmt::Display::fmt(code, f) } - Kind::RuntimeStartupFailure => f.write_str("Client runtime failed to start"), } } } @@ -285,7 +275,6 @@ impl StdError for Error { Kind::RedirectLoop => "Infinite redirect loop", Kind::ClientError(_) => "Client Error", Kind::ServerError(_) => "Server Error", - Kind::RuntimeStartupFailure => "Client runtime failed to start", } } @@ -309,8 +298,7 @@ impl StdError for Error { Kind::TooManyRedirects | Kind::RedirectLoop | Kind::ClientError(_) | - Kind::ServerError(_) | - Kind::RuntimeStartupFailure => None, + Kind::ServerError(_) => None, } } } @@ -335,7 +323,6 @@ pub(crate) enum Kind { RedirectLoop, ClientError(StatusCode), ServerError(StatusCode), - RuntimeStartupFailure, } @@ -502,10 +489,6 @@ pub(crate) fn url_bad_scheme(url: Url) -> Error { Error::new(Kind::UrlBadScheme, Some(url)) } -pub(crate) fn runtime_startup() -> Error { - Error::new(Kind::RuntimeStartupFailure, None) -} - #[cfg(test)] mod tests { use super::*;