1use machi_types::{ErrorCode, MachiError, RetryClass};
4
5pub type ToolError = MachiError;
7
8pub mod codes {
10 use super::{ErrorCode, MachiError, RetryClass};
11
12 #[must_use]
14 pub fn not_found(name: &str) -> MachiError {
15 MachiError::new(ErrorCode::ToolNotFound, format!("tool not found: {name}"))
16 }
17
18 #[must_use]
20 pub fn invalid_args(msg: impl Into<String>) -> MachiError {
21 MachiError::new(ErrorCode::ToolInvalidArgs, msg)
22 }
23
24 #[must_use]
26 pub fn execution(msg: impl Into<String>) -> MachiError {
27 MachiError::new(ErrorCode::ToolExecution, msg)
28 }
29
30 #[must_use]
32 pub fn timeout(msg: impl Into<String>) -> MachiError {
33 MachiError::new(ErrorCode::ToolTimeout, msg).with_retry(RetryClass::Backoff)
34 }
35
36 #[must_use]
38 pub fn cancelled() -> MachiError {
39 MachiError::new(ErrorCode::ToolCancelled, "tool call cancelled")
40 }
41
42 #[must_use]
44 pub fn denied(msg: impl Into<String>) -> MachiError {
45 MachiError::new(ErrorCode::ToolDenied, msg)
46 }
47
48 #[must_use]
50 pub fn approval_denied(msg: impl Into<String>) -> MachiError {
51 MachiError::new(ErrorCode::ToolApprovalDenied, msg)
52 }
53
54 #[must_use]
56 pub fn stream_protocol(msg: impl Into<String>) -> MachiError {
57 MachiError::new(ErrorCode::ToolStreamProtocol, msg)
58 }
59
60 #[must_use]
62 pub fn rate_limited(msg: impl Into<String>) -> MachiError {
63 MachiError::new(ErrorCode::ToolRateLimited, msg).with_retry(RetryClass::Backoff)
64 }
65
66 #[must_use]
68 pub fn concurrency_limit(msg: impl Into<String>) -> MachiError {
69 MachiError::new(ErrorCode::ToolConcurrencyLimit, msg)
70 }
71
72 #[must_use]
74 pub fn network(msg: impl Into<String>) -> MachiError {
75 MachiError::new(ErrorCode::ToolNetwork, msg).with_retry(RetryClass::Backoff)
76 }
77
78 #[must_use]
80 pub fn service_unavailable(msg: impl Into<String>) -> MachiError {
81 MachiError::new(ErrorCode::ToolServiceUnavailable, msg).with_retry(RetryClass::Backoff)
82 }
83}