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<futures::task::SpawnError> for Error
erroneously treat it as an internal error.  We will fix them in a moment.
This commit is contained in:
Ian Jackson 2022-01-21 15:45:41 +00:00
parent a623982197
commit 68d0ec437f
4 changed files with 25 additions and 0 deletions

3
Cargo.lock generated
View File

@ -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",

View File

@ -16,5 +16,7 @@ default = ["backtrace"]
[dependencies]
backtrace = { version = "0.3", optional = true }
derive_more = "0.99"
futures = "0.3"
thiserror = "1"
[dev-dependencies]

View File

@ -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
}
}
}

View File

@ -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"}