use thiserror::Error;
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum Error {
#[error("unwanted object: {0}")]
Unwanted(&'static str),
#[error("tried to download information on a DirMgr with no download support")]
NoDownloadSupport,
#[error("bad argument: {0}")]
BadArgument(&'static str),
#[error("corrupt cache: {0}")]
CacheCorruption(&'static str),
#[error("sqlite error: {0}")]
SqliteError(#[from] rusqlite::Error),
#[error("unrecognized data storage schema")]
UnrecognizedSchema,
#[error("directory updater has shut down")]
UpdaterShutdown,
#[error("bad network configuration")]
BadNetworkConfig(&'static str),
#[error("directory not present or not up-to-date")]
DirectoryNotPresent,
#[error("couldn't get write lock on directory cache")]
CacheIsLocked,
#[error("authorities on consensus do not match what we expect.")]
UnrecognizedAuthorities,
#[error("dirmgr has been dropped; background tasks exiting")]
ManagerDropped,
#[error("unable to finish bootstrapping a directory")]
CantAdvanceState,
#[error("runtime error: {0}")]
RuntimeError(String),
#[error("storage error: {0}")]
StorageError(String),
#[error("consdiff error: {0}")]
ConsensusDiffError(#[from] tor_consdiff::Error),
#[error("string parsing error: {0}")]
StringParsingError(String),
#[error("netdoc error: {0}")]
NetDocError(#[from] tor_netdoc::Error),
#[error("dirclient error: {0}")]
DirClientError(#[from] tor_dirclient::Error),
#[error("checkable error: {0}")]
SignatureError(#[from] signature::Error),
#[error("IO error: {0}")]
IOError(#[from] std::io::Error),
}
impl From<std::str::Utf8Error> for Error {
fn from(err: std::str::Utf8Error) -> Self {
Error::StringParsingError(err.to_string())
}
}
impl From<std::string::FromUtf8Error> for Error {
fn from(err: std::string::FromUtf8Error) -> Self {
Error::StringParsingError(err.to_string())
}
}
impl From<hex::FromHexError> for Error {
fn from(err: hex::FromHexError) -> Self {
Error::StringParsingError(err.to_string())
}
}
impl From<futures::task::SpawnError> for Error {
fn from(err: futures::task::SpawnError) -> Self {
Error::RuntimeError(err.to_string())
}
}