use machi_types::{ErrorCode, MachiError, RetryClass};
pub type ToolError = MachiError;
pub mod codes {
use super::{ErrorCode, MachiError, RetryClass};
#[must_use]
pub fn not_found(name: &str) -> MachiError {
MachiError::new(ErrorCode::ToolNotFound, format!("tool not found: {name}"))
}
#[must_use]
pub fn invalid_args(msg: impl Into<String>) -> MachiError {
MachiError::new(ErrorCode::ToolInvalidArgs, msg)
}
#[must_use]
pub fn execution(msg: impl Into<String>) -> MachiError {
MachiError::new(ErrorCode::ToolExecution, msg)
}
#[must_use]
pub fn timeout(msg: impl Into<String>) -> MachiError {
MachiError::new(ErrorCode::ToolTimeout, msg).with_retry(RetryClass::Backoff)
}
#[must_use]
pub fn cancelled() -> MachiError {
MachiError::new(ErrorCode::ToolCancelled, "tool call cancelled")
}
#[must_use]
pub fn denied(msg: impl Into<String>) -> MachiError {
MachiError::new(ErrorCode::ToolDenied, msg)
}
#[must_use]
pub fn approval_denied(msg: impl Into<String>) -> MachiError {
MachiError::new(ErrorCode::ToolApprovalDenied, msg)
}
#[must_use]
pub fn stream_protocol(msg: impl Into<String>) -> MachiError {
MachiError::new(ErrorCode::ToolStreamProtocol, msg)
}
#[must_use]
pub fn rate_limited(msg: impl Into<String>) -> MachiError {
MachiError::new(ErrorCode::ToolRateLimited, msg).with_retry(RetryClass::Backoff)
}
#[must_use]
pub fn concurrency_limit(msg: impl Into<String>) -> MachiError {
MachiError::new(ErrorCode::ToolConcurrencyLimit, msg)
}
#[must_use]
pub fn network(msg: impl Into<String>) -> MachiError {
MachiError::new(ErrorCode::ToolNetwork, msg).with_retry(RetryClass::Backoff)
}
#[must_use]
pub fn service_unavailable(msg: impl Into<String>) -> MachiError {
MachiError::new(ErrorCode::ToolServiceUnavailable, msg).with_retry(RetryClass::Backoff)
}
}