refactor(error): improve error message when tokio::spawn fails
Closes #1635
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
use std::error::Error as StdError;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ impl Exec {
|
|||||||
.spawn(Box::new(fut))
|
.spawn(Box::new(fut))
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("executor error: {:?}", err);
|
warn!("executor error: {:?}", err);
|
||||||
::Error::new_execute()
|
::Error::new_execute(TokioSpawnError)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "runtime"))]
|
#[cfg(not(feature = "runtime"))]
|
||||||
@@ -53,7 +54,7 @@ impl Exec {
|
|||||||
e.execute(Box::new(fut))
|
e.execute(Box::new(fut))
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("executor error: {:?}", err.kind());
|
warn!("executor error: {:?}", err.kind());
|
||||||
::Error::new_execute()
|
::Error::new_execute("custom executor failed")
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -101,7 +102,7 @@ where
|
|||||||
self.execute(fut)
|
self.execute(fut)
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("executor error: {:?}", err.kind());
|
warn!("executor error: {:?}", err.kind());
|
||||||
::Error::new_execute()
|
::Error::new_execute("custom executor failed")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,7 +118,30 @@ where
|
|||||||
self.execute(fut)
|
self.execute(fut)
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("executor error: {:?}", err.kind());
|
warn!("executor error: {:?}", err.kind());
|
||||||
::Error::new_execute()
|
::Error::new_execute("custom executor failed")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===== StdError impls =====
|
||||||
|
|
||||||
|
struct TokioSpawnError;
|
||||||
|
|
||||||
|
impl fmt::Debug for TokioSpawnError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
fmt::Debug::fmt("tokio::spawn failed (is a tokio runtime running this future?)", f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for TokioSpawnError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
fmt::Display::fmt("tokio::spawn failed (is a tokio runtime running this future?)", f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StdError for TokioSpawnError {
|
||||||
|
fn description(&self) -> &str {
|
||||||
|
"tokio::spawn failed"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
14
src/error.rs
14
src/error.rs
@@ -258,8 +258,8 @@ impl Error {
|
|||||||
Error::new(Kind::Shutdown, Some(Box::new(cause)))
|
Error::new(Kind::Shutdown, Some(Box::new(cause)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn new_execute() -> Error {
|
pub(crate) fn new_execute<E: Into<Cause>>(cause: E) -> Error {
|
||||||
Error::new(Kind::Execute, None)
|
Error::new(Kind::Execute, Some(cause.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn new_h2(cause: ::h2::Error) -> Error {
|
pub(crate) fn new_h2(cause: ::h2::Error) -> Error {
|
||||||
@@ -269,10 +269,12 @@ impl Error {
|
|||||||
|
|
||||||
impl fmt::Debug for Error {
|
impl fmt::Debug for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
f.debug_struct("Error")
|
let mut f = f.debug_struct("Error");
|
||||||
.field("kind", &self.inner.kind)
|
f.field("kind", &self.inner.kind);
|
||||||
.field("cause", &self.inner.cause)
|
if let Some(ref cause) = self.inner.cause {
|
||||||
.finish()
|
f.field("cause", cause);
|
||||||
|
}
|
||||||
|
f.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user