agentic_tools_core/
error.rs1use thiserror::Error;
4
5#[derive(Error, Debug)]
7pub enum ToolError {
8 #[error("invalid input: {0}")]
10 InvalidInput(String),
11
12 #[error("internal error: {0}")]
14 Internal(String),
15
16 #[error("external service error: {0}")]
18 External(String),
19
20 #[error("permission denied: {0}")]
22 Permission(String),
23
24 #[error("not found: {0}")]
26 NotFound(String),
27
28 #[error(
30 "cancelled{}",
31 .reason
32 .as_deref()
33 .map_or_else(String::new, |reason| format!(": {reason}"))
34 )]
35 Cancelled {
36 reason: Option<String>,
38 },
39}
40
41impl ToolError {
42 pub fn invalid_input<S: ToString>(s: S) -> Self {
44 ToolError::InvalidInput(s.to_string())
45 }
46
47 pub fn internal<S: ToString>(s: S) -> Self {
49 ToolError::Internal(s.to_string())
50 }
51
52 pub fn external<S: ToString>(s: S) -> Self {
54 ToolError::External(s.to_string())
55 }
56
57 pub fn not_found<S: ToString>(s: S) -> Self {
59 ToolError::NotFound(s.to_string())
60 }
61
62 pub fn permission<S: ToString>(s: S) -> Self {
64 ToolError::Permission(s.to_string())
65 }
66
67 pub fn cancelled(reason: Option<String>) -> Self {
69 ToolError::Cancelled { reason }
70 }
71}