use std::{
error::Error,
fmt,
sync::Arc,
};
#[derive(Clone, Debug)]
pub struct ReporterError {
source: Arc<dyn Error + Send + Sync + 'static>,
}
impl ReporterError {
pub fn new<E>(source: E) -> Self
where
E: Error + Send + Sync + 'static,
{
Self {
source: Arc::new(source),
}
}
pub fn message(message: &str) -> Self {
Self::new(MessageError(message.into()))
}
#[must_use]
pub fn source_error(&self) -> &(dyn Error + Send + Sync + 'static) {
self.source.as_ref()
}
}
impl fmt::Display for ReporterError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
self.source.fmt(formatter)
}
}
impl Error for ReporterError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
Some(self.source.as_ref())
}
}
#[derive(Debug)]
struct MessageError(String);
impl fmt::Display for MessageError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(&self.0)
}
}
impl Error for MessageError {}