use thiserror::Error;
#[derive(Debug, Error)]
pub enum LLMError {
#[error("HTTP error: {0}")]
HttpError(String),
#[error("Auth error: {0}")]
AuthError(String),
#[error("Invalid request: {0}")]
InvalidRequest(String),
#[error("Provider error: {0}")]
ProviderError(String),
#[error("Response format error: {message}. Raw response: {raw_response}")]
ResponseFormatError {
message: String,
raw_response: String,
},
#[error("Generic error: {0}")]
Generic(String),
#[error("JSON parse error: {0}")]
JsonError(String),
#[error("Tool configuration error: {0}")]
ToolConfigError(String),
#[error("Retry attempts exceeded after {attempts} tries: {last_error}")]
RetryExceeded { attempts: usize, last_error: String },
}
impl From<reqwest::Error> for LLMError {
fn from(err: reqwest::Error) -> Self {
LLMError::HttpError(err.to_string())
}
}
impl From<serde_json::Error> for LLMError {
fn from(err: serde_json::Error) -> Self {
LLMError::JsonError(format!(
"{} at line {} column {}",
err,
err.line(),
err.column()
))
}
}