labscript 0.1.0

Prescription PDF generator with e-signature and QR verification
use std::process;

#[derive(thiserror::Error, Debug)]
pub enum LabscriptError {
    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),

    #[error("JSON error: {0}")]
    Json(#[from] serde_json::Error),

    #[error("PDF generation error: {0}")]
    Pdf(String),

    #[error("Configuration error: {0}")]
    Config(String),

    #[error("Invalid input: {0}")]
    InvalidInput(String),
}

impl LabscriptError {
    pub fn exit_code(&self) -> i32 {
        match self {
            Self::Io(_) => 1,
            Self::Config(_) => 2,
            Self::InvalidInput(_) | Self::Json(_) => 3,
            Self::Pdf(_) => 1,
        }
    }

    pub fn exit(&self) -> ! {
        process::exit(self.exit_code());
    }
}