use std::fmt::{self, Debug, Formatter};
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("invalid token provided to internal function")]
InvalidToken,
#[error("underlying IO error")]
IoError(#[from] std::io::Error),
#[error("other error during loop operation")]
OtherError(#[from] Box<dyn std::error::Error + Sync + Send>),
}
impl From<Error> for std::io::Error {
fn from(err: Error) -> Self {
match err {
Error::IoError(source) => source,
Error::InvalidToken => Self::new(std::io::ErrorKind::InvalidInput, err.to_string()),
Error::OtherError(source) => Self::new(std::io::ErrorKind::Other, source),
}
}
}
pub type Result<T> = core::result::Result<T, Error>;
#[derive(thiserror::Error)]
#[error("error inserting event source")]
pub struct InsertError<T> {
pub inserted: T,
#[source]
pub error: Error,
}
impl<T> Debug for InsertError<T> {
#[cfg_attr(feature = "nightly_coverage", coverage(off))]
fn fmt(&self, formatter: &mut Formatter) -> core::result::Result<(), fmt::Error> {
write!(formatter, "{:?}", self.error)
}
}
impl<T> From<InsertError<T>> for crate::Error {
#[cfg_attr(feature = "nightly_coverage", coverage(off))]
fn from(e: InsertError<T>) -> crate::Error {
e.error
}
}