use std::fmt;
use std::error::Error;
#[derive(Debug)]
pub enum ClientError {
NotFound(String),
InvalidInput(String),
IoError(std::io::Error),
IndexOutOfBounds,
ToolNotFound,
InvalidEndpoint,
InvalidPrompt,
NetworkError,
InvalidResponse,
ModelConfigNotSet,
UnknownError,
}
impl fmt::Display for ClientError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ClientError::NotFound(ref msg) => write!(f, "NotFound: {}", msg),
ClientError::InvalidInput(ref msg) => write!(f, "InvalidInput: {}", msg),
ClientError::IoError(ref err) => write!(f, "IoError: {}", err),
ClientError::IndexOutOfBounds => write!(f, "Index out of bounds"),
ClientError::ToolNotFound => write!(f, "Tool not found"),
ClientError::InvalidEndpoint => write!(f, "Invalid endpoint"),
ClientError::InvalidPrompt => write!(f, "Invalid prompt"),
ClientError::NetworkError => write!(f, "Network error"),
ClientError::InvalidResponse => write!(f, "Invalid response"),
ClientError::ModelConfigNotSet => write!(f, "Model config not set"),
ClientError::UnknownError => write!(f, "Unknown error"),
}
}
}
impl Error for ClientError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
ClientError::IoError(ref err) => Some(err),
_ => None,
}
}
}
impl From<std::io::Error> for ClientError {
fn from(err: std::io::Error) -> Self {
ClientError::IoError(err)
}
}
impl From<String> for ClientError {
fn from(err: String) -> Self {
ClientError::InvalidInput(err)
}
}