From de17c64412fca9393fdf19097917ea9c75625709 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 3 Feb 2022 18:32:16 +0000 Subject: [PATCH] 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. --- crates/arti-client/src/err.rs | 13 ++++++++++--- crates/tor-chanmgr/src/err.rs | 12 +++++++++--- crates/tor-circmgr/src/err.rs | 13 ++++++++++--- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/crates/arti-client/src/err.rs b/crates/arti-client/src/err.rs index b11511b5c..37cb8f58c 100644 --- a/crates/arti-client/src/err.rs +++ b/crates/arti-client/src/err.rs @@ -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), } impl From for Error { @@ -62,8 +69,8 @@ impl From for Error { } } -impl From for Error { - fn from(_: futures::task::SpawnError) -> Error { - Error::Internal("Couldn't spawn channel reactor") +impl From for Error { + fn from(e: SpawnError) -> Error { + Arc::new(e).into() } } diff --git a/crates/tor-chanmgr/src/err.rs b/crates/tor-chanmgr/src/err.rs index d6e341049..5ff9cf75c 100644 --- a/crates/tor-chanmgr/src/err.rs +++ b/crates/tor-chanmgr/src/err.rs @@ -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), + /// Unable to spawn task + #[error("unable to spawn task")] + Spawn(#[from] Arc), + /// An internal error of some kind that should never occur. #[error("Internal error: {0}")] Internal(&'static str), } -impl From for Error { - fn from(_: futures::task::SpawnError) -> Error { - Error::Internal("Couldn't spawn channel reactor") +impl From for Error { + fn from(e: SpawnError) -> Error { + Arc::new(e).into() } } diff --git a/crates/tor-circmgr/src/err.rs b/crates/tor-circmgr/src/err.rs index bdbc1b484..15e9aea47 100644 --- a/crates/tor-circmgr/src/err.rs +++ b/crates/tor-circmgr/src/err.rs @@ -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), } impl From for Error { @@ -85,9 +92,9 @@ impl From for Error { } } -impl From for Error { - fn from(_: futures::task::SpawnError) -> Error { - Error::Internal("Unable to spawn new task in executor.".into()) +impl From for Error { + fn from(e: SpawnError) -> Error { + Arc::new(e).into() } }