2022-08-20 04:01:43 +00:00
|
|
|
use crate::colour;
|
|
|
|
|
|
|
|
use std::io;
|
|
|
|
use std::fmt;
|
2022-08-20 07:06:55 +00:00
|
|
|
use std::str;
|
2022-08-20 04:01:43 +00:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Error {
|
|
|
|
Io(io::Error),
|
|
|
|
Confy(confy::ConfyError),
|
|
|
|
Trash(trash::Error),
|
|
|
|
TomlDe(toml::de::Error),
|
|
|
|
TomlSer(toml::ser::Error),
|
2022-08-20 07:06:55 +00:00
|
|
|
Utf8(str::Utf8Error),
|
2022-08-20 23:58:05 +00:00
|
|
|
Fmt(fmt::Error),
|
2022-08-20 04:01:43 +00:00
|
|
|
Generic(String),
|
2022-08-25 06:40:56 +00:00
|
|
|
Internal(String),
|
2022-08-20 04:01:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for Error {
|
|
|
|
fn fmt(&self, f : &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
match self {
|
2022-08-29 09:38:21 +00:00
|
|
|
Error::Io(err) => write!(f, "{} {}", colour::text::error("Internal Error:"), err),
|
|
|
|
Error::Confy(err) => write!(f, "{} {}", colour::text::error("Internal Error:"), err),
|
|
|
|
Error::Trash(err) => write!(f, "{} {}", colour::text::error("Internal Error:"), err),
|
|
|
|
Error::TomlDe(err) => write!(f, "{} {}", colour::text::error("Internal Error:"), err),
|
|
|
|
Error::TomlSer(err) => write!(f, "{} {}", colour::text::error("Internal Error:"), err),
|
|
|
|
Error::Utf8(err) => write!(f, "{} {}", colour::text::error("Internal Error:"), err),
|
|
|
|
Error::Fmt(err) => write!(f, "{} {}", colour::text::error("Internal Error:"), err),
|
|
|
|
Error::Generic(message) => write!(f, "{} {}", colour::text::error("Error:"), message),
|
|
|
|
Error::Internal(message) => write!(f, "{} {}", colour::text::error("Internal Error:"), message),
|
2022-08-20 04:01:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<io::Error> for Error {
|
|
|
|
fn from(err : io::Error) -> Self {
|
|
|
|
Error::Io(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<confy::ConfyError> for Error {
|
|
|
|
fn from(err : confy::ConfyError) -> Self {
|
|
|
|
Error::Confy(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<trash::Error> for Error {
|
|
|
|
fn from(err : trash::Error) -> Self {
|
|
|
|
Error::Trash(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<toml::de::Error> for Error {
|
|
|
|
fn from(err : toml::de::Error) -> Self {
|
|
|
|
Error::TomlDe(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<toml::ser::Error> for Error {
|
|
|
|
fn from(err : toml::ser::Error) -> Self {
|
|
|
|
Error::TomlSer(err)
|
|
|
|
}
|
|
|
|
}
|
2022-08-20 07:06:55 +00:00
|
|
|
|
|
|
|
impl From<str::Utf8Error> for Error {
|
|
|
|
fn from(err : str::Utf8Error) -> Self {
|
|
|
|
Error::Utf8(err)
|
|
|
|
}
|
|
|
|
}
|
2022-08-20 23:58:05 +00:00
|
|
|
|
|
|
|
impl From<fmt::Error> for Error {
|
|
|
|
fn from(err : fmt::Error) -> Self {
|
|
|
|
Error::Fmt(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|