use thiserror::Error;
#[derive(Error, Debug)]
pub enum ToolError {
#[error("invalid input: {0}")]
InvalidInput(String),
#[error("internal error: {0}")]
Internal(String),
#[error("external service error: {0}")]
External(String),
#[error("permission denied: {0}")]
Permission(String),
#[error("not found: {0}")]
NotFound(String),
#[error(
"cancelled{}",
.reason
.as_deref()
.map_or_else(String::new, |reason| format!(": {reason}"))
)]
Cancelled {
reason: Option<String>,
},
}
impl ToolError {
pub fn invalid_input(s: impl Into<String>) -> Self {
Self::InvalidInput(s.into())
}
pub fn internal(s: impl Into<String>) -> Self {
Self::Internal(s.into())
}
pub fn external(s: impl Into<String>) -> Self {
Self::External(s.into())
}
pub fn not_found(s: impl Into<String>) -> Self {
Self::NotFound(s.into())
}
pub fn permission(s: impl Into<String>) -> Self {
Self::Permission(s.into())
}
pub fn cancelled(reason: Option<String>) -> Self {
Self::Cancelled { reason }
}
}