use std::error::Error;
use std::fmt::Display;
use uucore::display::Quotable;
use uucore::error::UError;
#[derive(Debug)]
pub enum TacError {
InvalidRegex(regex::Error),
InvalidArgument(String),
FileNotFound(String),
ReadError(String, std::io::Error),
WriteError(std::io::Error),
}
impl UError for TacError {
fn code(&self) -> i32 {
1
}
}
impl Error for TacError {}
impl Display for TacError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::InvalidRegex(e) => write!(f, "invalid regular expression: {e}"),
Self::InvalidArgument(s) => {
write!(f, "{}: read error: Invalid argument", s.maybe_quote())
}
Self::FileNotFound(s) => write!(
f,
"failed to open {} for reading: No such file or directory",
s.quote()
),
Self::ReadError(s, e) => write!(f, "failed to read from {s}: {e}"),
Self::WriteError(e) => write!(f, "failed to write to stdout: {e}"),
}
}
}