#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ErrorKind {
Config,
Runtime,
}
#[derive(Debug)]
pub struct AppError {
pub kind: ErrorKind,
pub message: String,
}
impl AppError {
pub fn config(msg: impl Into<String>) -> Self {
Self {
kind: ErrorKind::Config,
message: msg.into(),
}
}
pub fn runtime(msg: impl Into<String>) -> Self {
Self {
kind: ErrorKind::Runtime,
message: msg.into(),
}
}
}
impl std::fmt::Display for AppError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.message)
}
}
impl std::error::Error for AppError {}
pub fn exit_code_for(kind: ErrorKind) -> i32 {
match kind {
ErrorKind::Config => 1,
ErrorKind::Runtime => 2,
}
}