2021-07-07 20:54:14 +00:00
|
|
|
use thiserror::Error as ThisError;
|
|
|
|
|
|
|
|
pub type Result<T, E = Error> = std::result::Result<T, E>;
|
|
|
|
|
|
|
|
#[derive(ThisError, Debug)]
|
|
|
|
pub enum Error {
|
|
|
|
/// Used when errors need to propogate but are too unique to be typed
|
|
|
|
#[error("{0}")]
|
|
|
|
Unique(String),
|
|
|
|
|
|
|
|
#[error("I/O Error: {0}")]
|
|
|
|
IO(#[from] std::io::Error),
|
|
|
|
|
2022-02-09 08:11:02 +00:00
|
|
|
#[error("Format Error: {0}")]
|
|
|
|
FormatError(#[from] std::fmt::Error),
|
|
|
|
|
|
|
|
#[error("Format failed: {0}")]
|
|
|
|
ParseError(String),
|
|
|
|
|
|
|
|
#[error("Runtime Error: {0}")]
|
|
|
|
RuntimeError(String),
|
|
|
|
|
2021-07-07 20:54:14 +00:00
|
|
|
#[error("Failed to write error")]
|
|
|
|
FailedToWrite,
|
|
|
|
|
2022-03-25 13:54:18 +00:00
|
|
|
#[error("Build Failed: {0}")]
|
2021-12-29 17:03:18 +00:00
|
|
|
BuildFailed(String),
|
|
|
|
|
2022-03-25 13:54:18 +00:00
|
|
|
#[error("Cargo Error: {0}")]
|
2021-07-07 20:54:14 +00:00
|
|
|
CargoError(String),
|
|
|
|
|
2022-02-09 08:11:02 +00:00
|
|
|
#[error("{0}")]
|
|
|
|
CustomError(String),
|
|
|
|
|
2021-07-07 20:54:14 +00:00
|
|
|
#[error(transparent)]
|
|
|
|
Other(#[from] anyhow::Error),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<&str> for Error {
|
|
|
|
fn from(s: &str) -> Self {
|
|
|
|
Error::Unique(s.to_string())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<String> for Error {
|
|
|
|
fn from(s: String) -> Self {
|
|
|
|
Error::Unique(s)
|
|
|
|
}
|
|
|
|
}
|
2022-02-09 08:11:02 +00:00
|
|
|
|
|
|
|
impl From<html_parser::Error> for Error {
|
|
|
|
fn from(e: html_parser::Error) -> Self {
|
|
|
|
Self::ParseError(e.to_string())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<hyper::Error> for Error {
|
|
|
|
fn from(e: hyper::Error) -> Self {
|
|
|
|
Self::RuntimeError(e.to_string())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! custom_error {
|
|
|
|
($msg:literal $(,)?) => {
|
2022-08-27 07:18:44 +00:00
|
|
|
Err(Error::CustomError(format!($msg)))
|
2022-02-09 08:11:02 +00:00
|
|
|
};
|
|
|
|
($err:expr $(,)?) => {
|
|
|
|
Err(Error::from($err))
|
|
|
|
};
|
|
|
|
($fmt:expr, $($arg:tt)*) => {
|
|
|
|
Err(Error::CustomError(format!($fmt, $($arg)*)))
|
|
|
|
};
|
|
|
|
}
|