diff --git a/Cargo.lock b/Cargo.lock index 55d407732..e1153c3e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3028,6 +3028,7 @@ dependencies = [ "memchr", "thiserror", "tor-circmgr", + "tor-error", "tor-llcrypto", "tor-netdoc", "tor-proto", diff --git a/crates/tor-dirclient/Cargo.toml b/crates/tor-dirclient/Cargo.toml index 43e67eaac..353d71c03 100644 --- a/crates/tor-dirclient/Cargo.toml +++ b/crates/tor-dirclient/Cargo.toml @@ -19,6 +19,7 @@ routerdesc = [] [dependencies] tor-circmgr = { path="../tor-circmgr", version = "0.0.4"} +tor-error = { path="../tor-error", version = "0.0.1"} tor-llcrypto = { path="../tor-llcrypto", version = "0.0.3"} tor-proto = { path="../tor-proto", version = "0.0.4"} tor-netdoc = { path="../tor-netdoc", version = "0.0.4"} diff --git a/crates/tor-dirclient/src/err.rs b/crates/tor-dirclient/src/err.rs index 825e84a9f..1812124c3 100644 --- a/crates/tor-dirclient/src/err.rs +++ b/crates/tor-dirclient/src/err.rs @@ -3,6 +3,7 @@ use std::sync::Arc; use thiserror::Error; +use tor_error::{ErrorKind, HasKind}; use tor_rtcompat::TimeoutError; /// An error originating from the tor-dirclient crate. @@ -81,3 +82,26 @@ impl Error { true } } + +impl HasKind for Error { + fn kind(&self) -> ErrorKind { + use Error as E; + use ErrorKind as EK; + match self { + E::DirTimeout => EK::ExitTimeout, + E::TruncatedHeaders => EK::TorProtocolViolation, + E::HttpStatus(_) => EK::RemoteRefused, + E::ResponseTooLong(_) => EK::TorProtocolViolation, + E::Utf8Encoding(_) => EK::TorProtocolViolation, + // TODO: it would be good to get more information out of the IoError + // in this case, but that would require a bunch of gnarly + // downcasting. + E::IoError(_) => EK::RemoteStreamError, + E::Proto(e) => e.kind(), + E::CircMgr(e) => e.kind(), + E::HttparseError(_) => EK::TorProtocolViolation, + E::HttpError(_) => EK::Internal, + E::ContentEncoding(_) => EK::TorProtocolViolation, + } + } +}