1//! Declare error type for tor-netdir
23use thiserror::Error;
4use tor_error::HasKind;
56/// An error returned by the network directory code
7#[derive(Error, Clone, Debug)]
8#[non_exhaustive]
9pub enum Error {
10/// We don't have enough directory info to build circuits
11#[error("Not enough directory information to build circuits")]
12NotEnoughInfo,
13/// We don't have any directory information.
14#[error("No directory information available")]
15NoInfo,
16/// We have directory information, but it is too expired to use.
17#[error("Directory is expired, and we haven't got a new one yet")]
18DirExpired,
19/// We have directory information, but it is too expired to use.
20#[error("Directory is published too far in the future: Your clock is probably wrong")]
21DirNotYetValid,
22/// We received a consensus document that should be impossible.
23#[error("Invalid information from consensus document: {0}")]
24InvalidConsensus(&'static str),
25}
2627impl HasKind for Error {
28fn kind(&self) -> tor_error::ErrorKind {
29use tor_error::ErrorKind as EK;
30use Error as E;
31match 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}
3940/// An error returned when looking up onion service directories.
41#[derive(Error, Clone, Debug)]
42#[cfg(feature = "hs-common")]
43#[cfg_attr(docsrs, doc(cfg(feature = "hs-common")))]
44#[non_exhaustive]
45pub enum OnionDirLookupError {
46/// We tried to look up an onion service directory for a time period that
47 /// did not correspond to one of our hash rings.
48#[error("Tried to look up an onion service directory for an invalid time period.")]
49WrongTimePeriod,
50}
5152#[cfg(feature = "hs-common")]
53impl HasKind for OnionDirLookupError {
54fn kind(&self) -> tor_error::ErrorKind {
55use tor_error::ErrorKind as EK;
56use OnionDirLookupError as E;
57match self {
58 E::WrongTimePeriod => EK::BadApiUsage,
59 }
60 }
61}