use std::process;
#[derive(thiserror::Error, Debug)]
pub enum SupplementsError {
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("Database error: {0}")]
Db(#[from] rusqlite::Error),
#[error("TOML parse error: {0}")]
Toml(#[from] toml::de::Error),
#[error("Configuration error: {0}")]
Config(String),
#[error("Patient not found: {0}")]
PatientNotFound(String),
#[error("Product not found: {0}")]
ProductNotFound(String),
#[error("Invalid input: {0}")]
#[allow(dead_code)]
InvalidInput(String),
#[error("No input provided. Use <slug>, --stdin, or pipe labassess JSON")]
NoInput,
}
impl SupplementsError {
pub fn exit_code(&self) -> i32 {
match self {
Self::Config(_) => 2,
Self::PatientNotFound(_) | Self::ProductNotFound(_) => 3,
Self::InvalidInput(_) | Self::NoInput => 3,
_ => 1,
}
}
pub fn exit(&self) -> ! {
process::exit(self.exit_code());
}
}