use std::error::Error;
use std::fmt::{self, Display};
#[derive(Debug)]
pub enum ClientError {
InternalError {
source: Box<dyn Error + Send + Sync>,
},
DomainParsingError {
kind: addr::error::Kind,
input: String,
},
ConfigError { source: redact_config::ConfigError },
CryptoError { source: redact_crypto::CryptoError },
SourceError { source: redact_crypto::SourceError },
}
impl Error for ClientError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match *self {
ClientError::InternalError { ref source } => Some(source.as_ref()),
ClientError::DomainParsingError { .. } => None,
ClientError::ConfigError { ref source } => Some(source),
ClientError::CryptoError { ref source } => Some(source),
ClientError::SourceError { ref source } => Some(source),
}
}
}
impl Display for ClientError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
ClientError::InternalError { .. } => {
write!(f, "Internal error occurred")
}
ClientError::DomainParsingError {
ref kind,
ref input,
} => {
write!(
f,
"Error occurred during domain parsing ({:?}) on input: {}",
kind, input
)
}
ClientError::ConfigError { .. } => {
write!(f, "Error occured when handling config")
}
ClientError::CryptoError { .. } => {
write!(f, "Error occured in crypto library")
}
ClientError::SourceError { .. } => {
write!(f, "Error occured while handling a source")
}
}
}
}