pub type Result<T> = std::result::Result<T, PmpxError>;
pub const EXIT_OK: u8 = 0;
pub const EXIT_INTERNAL: u8 = 1;
pub const EXIT_USAGE: u8 = 2;
pub const EXIT_NOT_FOUND: u8 = 3;
#[derive(Debug, thiserror::Error)]
pub enum PmpxError {
#[error("{0}")]
Usage(String),
#[error("{0}")]
NotFound(String),
#[error(transparent)]
Other(#[from] anyhow::Error),
#[error("{0}")]
Backend(String, u8),
}
impl PmpxError {
pub fn exit_code(&self) -> u8 {
match self {
PmpxError::Usage(_) => EXIT_USAGE,
PmpxError::NotFound(_) => EXIT_NOT_FOUND,
PmpxError::Other(_) => EXIT_INTERNAL,
PmpxError::Backend(_, code) => *code,
}
}
pub fn not_found(message: impl Into<String>) -> Self {
PmpxError::NotFound(message.into())
}
}