fix(lib): return an error instead of panic if execute fails
If executing an internal task fails, a new variant of `hyper::Error` is returned to the user, with improved messaging. If a non-critical task fails to spawn, it no longer panics, instead just logging a warning. Closes #1566
This commit is contained in:
@@ -13,7 +13,7 @@ pub(crate) enum Exec {
|
||||
|
||||
|
||||
impl Exec {
|
||||
pub(crate) fn execute<F>(&self, fut: F)
|
||||
pub(crate) fn execute<F>(&self, fut: F) -> ::Result<()>
|
||||
where
|
||||
F: Future<Item=(), Error=()> + Send + 'static,
|
||||
{
|
||||
@@ -21,7 +21,13 @@ impl Exec {
|
||||
Exec::Default => {
|
||||
#[cfg(feature = "runtime")]
|
||||
{
|
||||
::tokio_executor::spawn(fut)
|
||||
use ::tokio_executor::Executor;
|
||||
::tokio_executor::DefaultExecutor::current()
|
||||
.spawn(Box::new(fut))
|
||||
.map_err(|err| {
|
||||
warn!("executor error: {:?}", err);
|
||||
::Error::new_execute()
|
||||
})
|
||||
}
|
||||
#[cfg(not(feature = "runtime"))]
|
||||
{
|
||||
@@ -30,10 +36,11 @@ impl Exec {
|
||||
}
|
||||
},
|
||||
Exec::Executor(ref e) => {
|
||||
let _ = e.execute(Box::new(fut))
|
||||
e.execute(Box::new(fut))
|
||||
.map_err(|err| {
|
||||
panic!("executor error: {:?}", err.kind());
|
||||
});
|
||||
warn!("executor error: {:?}", err.kind());
|
||||
::Error::new_execute()
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user