use std::io;
use std::path::PathBuf;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum AiError {
#[error("{0}")]
Usage(String),
#[error("{0}")]
Model(String),
#[error("{0}")]
Apply(String),
#[error("{0}")]
Io(String),
}
impl AiError {
pub fn is_usage(&self) -> bool {
matches!(self, Self::Usage(_))
}
pub(crate) fn usage(msg: impl ToString) -> Self {
Self::Usage(msg.to_string())
}
pub(crate) fn io_path(path: &std::path::Path, err: io::Error) -> Self {
Self::Io(format!("{}: {err}", path.display()))
}
pub(crate) fn missing(path: PathBuf) -> Self {
Self::Usage(format!("file not found: {}", path.display()))
}
}
impl From<io::Error> for AiError {
fn from(err: io::Error) -> Self {
Self::Io(err.to_string())
}
}