use std::io;
use std::path::PathBuf;
use thiserror::Error;
use vernier_core::EvalError;
pub(crate) const EXIT_VALIDATION: i32 = 2;
pub(crate) const EXIT_RUNTIME: i32 = 1;
#[derive(Debug, Error)]
pub(crate) enum CliError {
#[error("invalid arguments: {0}")]
Validation(String),
#[error("failed to read {path}: {source}")]
InputRead {
path: PathBuf,
#[source]
source: io::Error,
},
#[error("failed to write {path}: {source}")]
OutputWrite {
path: PathBuf,
#[source]
source: io::Error,
},
#[error("io: {0}")]
Io(#[from] io::Error),
#[error("invalid sigmas file: {0}")]
InvalidSigmas(String),
#[error("json serialization: {0}")]
JsonSerialize(#[from] serde_json::Error),
#[error("eval: {0}")]
Eval(#[from] EvalError),
}
impl CliError {
pub(crate) fn exit_code(&self) -> i32 {
match self {
Self::Validation(_) => EXIT_VALIDATION,
_ => EXIT_RUNTIME,
}
}
}