use std::error::Error as StdError;
use std::fmt;
#[derive(Debug)]
pub enum Error {
ConfigParseErr,
ConfigFormatErr,
CurrentDirErr,
TomlReadErr,
LinkStyleErr,
CreateFileErr,
WriteErr,
IoErr,
UnknownErr
}
impl Error {
pub fn is_fatal(&self) -> bool {
true
}
pub fn exit(&self) -> ! {
if self.is_fatal() {
wlnerr!("{}", self);
::std::process::exit(1)
} else {
println!("{}", self);
::std::process::exit(0)
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
_ => write!(f, "{}", self.description()),
}
}
}
impl StdError for Error {
fn description(&self) -> &str {
match *self {
Error::ConfigParseErr => "error parsing config file",
Error::ConfigFormatErr => "incorrect format for config file",
Error::CurrentDirErr => "cannot get current directory",
Error::TomlReadErr => "cannot read TOML config file",
Error::LinkStyleErr => "unrecognized link-style field",
Error::CreateFileErr => "cannot create output file",
Error::WriteErr => "cannot write to output file or stream",
Error::UnknownErr => "unknown fatal error",
Error::IoErr => "fatal i/o error with output file",
}
}
fn cause(&self) -> Option<&StdError> {
match *self {
_ => None,
}
}
}