use std::process;
#[derive(thiserror::Error, Debug)]
pub enum DeviceError {
#[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("Device not found: {0}")]
DeviceNotFound(String),
#[error("Invalid input: {0}")]
InvalidInput(String),
#[error("No input provided. Use <slug>, --stdin, or pipe labassess JSON")]
NoInput,
}
impl DeviceError {
pub fn exit_code(&self) -> i32 {
match self {
Self::Config(_) => 2,
Self::PatientNotFound(_) | Self::DeviceNotFound(_) => 3,
Self::InvalidInput(_) | Self::NoInput => 3,
_ => 1,
}
}
pub fn exit(&self) -> ! {
process::exit(self.exit_code());
}
}