use std::error::Error;
use std::fmt::{Display, Formatter};
#[derive(Debug)]
pub enum AiError {
Io(std::io::Error),
Utf8(std::string::FromUtf8Error),
CommandFailed(String),
}
impl Display for AiError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::Io(err) => write!(f, "io error: {}", err),
Self::Utf8(err) => write!(f, "utf8 error: {}", err),
Self::CommandFailed(msg) => write!(f, "command failed: {}", msg),
}
}
}
impl Error for AiError {}
impl From<std::io::Error> for AiError {
fn from(value: std::io::Error) -> Self {
Self::Io(value)
}
}
impl From<std::string::FromUtf8Error> for AiError {
fn from(value: std::string::FromUtf8Error) -> Self {
Self::Utf8(value)
}
}