use thiserror::Error;
use tor_error::HasKind;
#[derive(Error, Clone, Debug)]
#[non_exhaustive]
pub enum Error {
#[error("Not enough directory information to build circuits")]
NotEnoughInfo,
#[error("No directory information available")]
NoInfo,
#[error("Directory is expired, and we haven't got a new one yet")]
DirExpired,
#[error("Directory is published too far in the future: Your clock is probably wrong")]
DirNotYetValid,
#[error("Invalid information from consensus document: {0}")]
InvalidConsensus(&'static str),
}
impl HasKind for Error {
fn kind(&self) -> tor_error::ErrorKind {
use Error as E;
use tor_error::ErrorKind as EK;
match self {
E::DirExpired => EK::DirectoryExpired,
E::DirNotYetValid => EK::ClockSkew,
E::NotEnoughInfo | E::NoInfo => EK::BootstrapRequired,
E::InvalidConsensus(_) => EK::TorProtocolViolation,
}
}
}
#[derive(Error, Clone, Debug)]
#[non_exhaustive]
#[cfg(feature = "hs-common")]
pub enum VerbatimCircTargetDecodeError {
#[error("Unable to decode relay information")]
CantDecode(#[from] tor_linkspec::decode::ChanTargetDecodeError),
#[error("Impossible combination of identities")]
ImpossibleIds(#[source] crate::RelayLookupError),
#[error("Received an unsupported onion key type")]
UnsupportedOnionKey,
#[error("Internal error")]
Internal(#[from] tor_error::Bug),
}
#[derive(Error, Clone, Debug)]
#[cfg(feature = "hs-common")]
#[non_exhaustive]
pub enum OnionDirLookupError {
#[error("Tried to look up an onion service directory for an invalid time period.")]
WrongTimePeriod,
}
#[cfg(feature = "hs-common")]
impl HasKind for OnionDirLookupError {
fn kind(&self) -> tor_error::ErrorKind {
use OnionDirLookupError as E;
use tor_error::ErrorKind as EK;
match self {
E::WrongTimePeriod => EK::BadApiUsage,
}
}
}