spawn errors: Fix arti-client, tor-chanmgr, tor-circmgr

Provide an enum variant to contain the SpawnError and a From impl.

We use `#[from]` here because it doesn't really make sense to attach
any context, as it's not likely to be very relevant.
This commit is contained in:
Ian Jackson 2022-02-03 18:32:16 +00:00
parent 68d0ec437f
commit de17c64412
3 changed files with 29 additions and 9 deletions

View File

@ -1,5 +1,8 @@
//! Declare tor client specific errors.
use std::sync::Arc;
use futures::task::SpawnError;
use thiserror::Error;
use tor_rtcompat::TimeoutError;
@ -54,6 +57,10 @@ pub enum Error {
/// Unable to change configuration.
#[error("Reconfiguration failed: {0}")]
Reconfigure(#[from] tor_config::ReconfigureError),
/// Unable to spawn task
#[error("unable to spawn task")]
Spawn(#[from] Arc<SpawnError>),
}
impl From<TimeoutError> for Error {
@ -62,8 +69,8 @@ impl From<TimeoutError> for Error {
}
}
impl From<futures::task::SpawnError> for Error {
fn from(_: futures::task::SpawnError) -> Error {
Error::Internal("Couldn't spawn channel reactor")
impl From<SpawnError> for Error {
fn from(e: SpawnError) -> Error {
Arc::new(e).into()
}
}

View File

@ -1,6 +1,8 @@
//! Declare error types for tor-chanmgr
use std::sync::Arc;
use futures::task::SpawnError;
use thiserror::Error;
/// An error returned by a channel manager.
@ -27,14 +29,18 @@ pub enum Error {
#[error("I/O error while opening a channel: {0}")]
Io(#[source] Arc<std::io::Error>),
/// Unable to spawn task
#[error("unable to spawn task")]
Spawn(#[from] Arc<SpawnError>),
/// An internal error of some kind that should never occur.
#[error("Internal error: {0}")]
Internal(&'static str),
}
impl From<futures::task::SpawnError> for Error {
fn from(_: futures::task::SpawnError) -> Error {
Error::Internal("Couldn't spawn channel reactor")
impl From<SpawnError> for Error {
fn from(e: SpawnError) -> Error {
Arc::new(e).into()
}
}

View File

@ -1,5 +1,8 @@
//! Declare an error type for tor-circmgr
use std::sync::Arc;
use futures::task::SpawnError;
use retry_error::RetryError;
use thiserror::Error;
@ -77,6 +80,10 @@ pub enum Error {
/// We have an expired consensus
#[error("Consensus is expired")]
ExpiredConsensus,
/// Unable to spawn task
#[error("unable to spawn task")]
Spawn(#[from] Arc<SpawnError>),
}
impl From<futures::channel::oneshot::Canceled> for Error {
@ -85,9 +92,9 @@ impl From<futures::channel::oneshot::Canceled> for Error {
}
}
impl From<futures::task::SpawnError> for Error {
fn from(_: futures::task::SpawnError) -> Error {
Error::Internal("Unable to spawn new task in executor.".into())
impl From<SpawnError> for Error {
fn from(e: SpawnError) -> Error {
Arc::new(e).into()
}
}