From 68d0ec437f0068335251fe8bf5971a16fb063268 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 21 Jan 2022 15:45:41 +0000 Subject: [PATCH] spawn errors: impl HasKind for futures::SpawnError This needs two kinds. We have decided to treat a non-shutdown SpawnError as "unexplained" rather than as an InternalError. There are many crates whose From for Error erroneously treat it as an internal error. We will fix them in a moment. --- Cargo.lock | 3 +++ crates/tor-error/Cargo.toml | 2 ++ crates/tor-error/src/lib.rs | 19 +++++++++++++++++++ crates/tor-guardmgr/Cargo.toml | 1 + 4 files changed, 25 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 87ae67760..52321cac1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3078,6 +3078,8 @@ version = "0.0.1" dependencies = [ "backtrace", "derive_more", + "futures", + "thiserror", ] [[package]] @@ -3107,6 +3109,7 @@ dependencies = [ "serde", "thiserror", "tor-config", + "tor-error", "tor-linkspec", "tor-llcrypto", "tor-netdir", diff --git a/crates/tor-error/Cargo.toml b/crates/tor-error/Cargo.toml index d182e68d4..1e14ad770 100644 --- a/crates/tor-error/Cargo.toml +++ b/crates/tor-error/Cargo.toml @@ -16,5 +16,7 @@ default = ["backtrace"] [dependencies] backtrace = { version = "0.3", optional = true } derive_more = "0.99" +futures = "0.3" +thiserror = "1" [dev-dependencies] diff --git a/crates/tor-error/src/lib.rs b/crates/tor-error/src/lib.rs index 0d698b072..43072bd9c 100644 --- a/crates/tor-error/src/lib.rs +++ b/crates/tor-error/src/lib.rs @@ -77,6 +77,14 @@ pub enum ErrorKind { #[display(fmt = "could not write to read-only persistent state")] PersistentStateReadOnly, + /// Tor client's Rust async reactor is shutting down + #[display(fmt = "shutting down")] + ReactorShuttingDown, + + /// Tor client's Rust async reactor could not spawn a task for unexplained reasons + #[display(fmt = "unexplained rust async task spawn failure")] + UnexplainedTaskSpawnFailure, + /// Internal error (bug) /// /// A supposedly impossible problem has arisen. This indicates a bug in Arti. @@ -89,3 +97,14 @@ pub trait HasKind { /// The kind fn kind(&self) -> ErrorKind; } + +impl HasKind for futures::task::SpawnError { + fn kind(&self) -> ErrorKind { + use ErrorKind as EK; + if self.is_shutdown() { + EK::ReactorShuttingDown + } else { + EK::UnexplainedTaskSpawnFailure + } + } +} diff --git a/crates/tor-guardmgr/Cargo.toml b/crates/tor-guardmgr/Cargo.toml index 114825b03..07df94622 100644 --- a/crates/tor-guardmgr/Cargo.toml +++ b/crates/tor-guardmgr/Cargo.toml @@ -19,6 +19,7 @@ testing = [] [dependencies] tor-config = { path="../tor-config", version = "0.0.4"} +tor-error = { path="../tor-error", version = "0.0.1" } tor-netdir = { path="../tor-netdir", version = "0.0.4"} tor-linkspec = { path="../tor-linkspec", version = "0.0.3"} tor-llcrypto = { path="../tor-llcrypto", version = "0.0.3"}