use std::fmt;
#[derive(Debug, Clone)]
pub enum Error {
ModelNotAvailable,
GenerationError(String),
InvalidInput(String),
InternalError(String),
PoisonError,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::ModelNotAvailable => {
write!(
f,
"Foundation Model not available. Enable Apple Intelligence in System Settings."
)
}
Error::GenerationError(msg) => {
write!(f, "Generation error: {}", msg)
}
Error::InvalidInput(msg) => {
write!(f, "Invalid input: {}", msg)
}
Error::InternalError(msg) => {
write!(f, "Internal error: {}", msg)
}
Error::PoisonError => {
write!(
f,
"Synchronization primitive poisoned due to panic while holding lock"
)
}
}
}
}
impl std::error::Error for Error {}
pub type Result<T> = std::result::Result<T, Error>;