From 0a1cda688697eac119476388b4dd5ef74e9e7cb1 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 26 Jan 2022 17:27:27 +0000 Subject: [PATCH] tor-chanmgr::Error: impl HasKind --- crates/tor-chanmgr/src/err.rs | 13 +++++++++++++ crates/tor-error/src/lib.rs | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/crates/tor-chanmgr/src/err.rs b/crates/tor-chanmgr/src/err.rs index b0bd0af91..b49b8ce5d 100644 --- a/crates/tor-chanmgr/src/err.rs +++ b/crates/tor-chanmgr/src/err.rs @@ -6,6 +6,8 @@ use std::sync::Arc; use futures::task::SpawnError; use thiserror::Error; +use tor_error::ErrorKind; + /// An error returned by a channel manager. #[derive(Debug, Error, Clone)] #[non_exhaustive] @@ -63,3 +65,14 @@ impl From> for Error { Error::Internal("Thread failed while holding lock") } } + +impl tor_error::HasKind for Error { + fn kind(&self) -> ErrorKind { + use Error as E; + use ErrorKind as EK; + match self { + E::Io { .. } => EK::TorConnectionFailed, + _ => EK::TODO, + } + } +} diff --git a/crates/tor-error/src/lib.rs b/crates/tor-error/src/lib.rs index 1f7d8628a..1a7328fdd 100644 --- a/crates/tor-error/src/lib.rs +++ b/crates/tor-error/src/lib.rs @@ -52,6 +52,14 @@ pub use internal::*; #[derive(Debug, Clone, Copy, PartialEq, Eq, Display)] #[non_exhaustive] pub enum ErrorKind { + /// Error connecting to the Tor network + /// + /// Perhaps the local network is not working, or perhaps the chosen relay is not working + /// properly. Not used for errors that occur within the Tor network, or accessing the public + /// internet on the far side of Tor. + #[display(fmt = "error connecting to Tor")] + TorConnectionFailed, + /// IO error accessing local persistent state /// /// Eg, disk full or permissions problem.