1use thiserror::Error;
4use tor_error::HasKind;
5
6#[derive(Error, Clone, Debug)]
8#[non_exhaustive]
9pub enum Error {
10 #[error("Not enough directory information to build circuits")]
12 NotEnoughInfo,
13 #[error("No directory information available")]
15 NoInfo,
16 #[error("Directory is expired, and we haven't got a new one yet")]
18 DirExpired,
19 #[error("Directory is published too far in the future: Your clock is probably wrong")]
21 DirNotYetValid,
22 #[error("Invalid information from consensus document: {0}")]
24 InvalidConsensus(&'static str),
25}
26
27impl HasKind for Error {
28 fn kind(&self) -> tor_error::ErrorKind {
29 use Error as E;
30 use tor_error::ErrorKind as EK;
31 match self {
32 E::DirExpired => EK::DirectoryExpired,
33 E::DirNotYetValid => EK::ClockSkew,
34 E::NotEnoughInfo | E::NoInfo => EK::BootstrapRequired,
35 E::InvalidConsensus(_) => EK::TorProtocolViolation,
36 }
37 }
38}
39
40#[derive(Error, Clone, Debug)]
42#[cfg(feature = "hs-common")]
43#[non_exhaustive]
44pub enum OnionDirLookupError {
45 #[error("Tried to look up an onion service directory for an invalid time period.")]
48 WrongTimePeriod,
49}
50
51#[cfg(feature = "hs-common")]
52impl HasKind for OnionDirLookupError {
53 fn kind(&self) -> tor_error::ErrorKind {
54 use OnionDirLookupError as E;
55 use tor_error::ErrorKind as EK;
56 match self {
57 E::WrongTimePeriod => EK::BadApiUsage,
58 }
59 }
60}