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: impl Into<String>) -> Self {
44 Self::InvalidInput(s.into())
45 }
46
47 pub fn internal(s: impl Into<String>) -> Self {
49 Self::Internal(s.into())
50 }
51
52 pub fn external(s: impl Into<String>) -> Self {
54 Self::External(s.into())
55 }
56
57 pub fn not_found(s: impl Into<String>) -> Self {
59 Self::NotFound(s.into())
60 }
61
62 pub fn permission(s: impl Into<String>) -> Self {
64 Self::Permission(s.into())
65 }
66
67 pub fn cancelled(reason: Option<String>) -> Self {
69 Self::Cancelled { reason }
70 }
71}