use thiserror::Error;
#[derive(Debug, Error)]
pub enum E6Error {
#[error("i/o error: {0}")]
IO(#[from] std::io::Error),
#[error("infallible conversion error: {0}")]
InfallibleConversion(#[from] std::convert::Infallible),
#[error("boundbook error: {0}")]
BoundBook(#[from] boundbook::BbfError),
#[error("csv error: {0}")]
Csv(#[from] csv::Error),
#[error("redb transaction error: {0}")]
RedbTransaction(#[from] redb::TransactionError),
#[error("redb table error: {0}")]
RedbTable(#[from] redb::TableError),
#[error("redb storage error: {0}")]
RedbStorage(#[from] redb::StorageError),
#[error("redb commit error: {0}")]
RedbCommit(#[from] redb::CommitError),
#[error("system time error: {0}")]
SystemTime(#[from] std::time::SystemTimeError),
#[error("{0}")]
EyreReport(#[from] color_eyre::Report),
#[error("{0}")]
MietteReport(miette::Report),
#[error("reqwest error: {0}")]
Reqwest(#[from] reqwest::Error),
#[error("qr code error: {0}")]
QR(#[from] qrcode::types::QrError),
#[error("json error: {0}")]
Json(#[from] serde_json::Error),
#[error("toml serialization error: {0}")]
TOMLSer(#[from] toml::ser::Error),
#[error("error installing miette hook: {0}")]
MietteInstall(#[from] miette::InstallError),
#[error("tokio acquire error: {0}")]
TokioAcquire(#[from] tokio::sync::AcquireError),
#[error("int parse error: {0}")]
ParseInt(#[from] std::num::ParseIntError),
#[error("error parsing address: {0}")]
ParseAddr(#[from] std::net::AddrParseError),
#[error("error: {0}")]
Other(String),
}
impl From<String> for E6Error {
fn from(value: String) -> Self {
Self::Other(value)
}
}
impl From<miette::Report> for E6Error {
fn from(value: miette::Report) -> Self {
Self::MietteReport(value)
}
}
pub type Result<T, U = E6Error> = miette::Result<T, U>;
pub struct Report;
impl Report {
#[allow(clippy::new_ret_no_self)]
pub fn new<T>(e: T) -> E6Error
where
E6Error: std::convert::From<T>,
T: Into<E6Error>,
{
E6Error::from(e)
}
}
#[macro_export]
macro_rules! bail {
($msg:literal $(,)?) => {
return Err($crate::error::E6Error::from(String::from($msg)))
};
($err:expr $(,)?) => {
return Err($crate::error::E6Error::from($err))
};
($fmt:expr, $($arg:tt)*) => {
return Err($crate::error::E6Error::from(format!($fmt, $($arg)*)))
};
}