Skip to main content

agentic_tools_core/
error.rs

1//! Unified error type for agentic tools.
2
3use thiserror::Error;
4
5/// Error type returned by tool operations.
6#[derive(Error, Debug)]
7pub enum ToolError {
8    /// Invalid input provided to the tool.
9    #[error("invalid input: {0}")]
10    InvalidInput(String),
11
12    /// Internal error during tool execution.
13    #[error("internal error: {0}")]
14    Internal(String),
15
16    /// Error from an external service.
17    #[error("external service error: {0}")]
18    External(String),
19
20    /// Permission denied for the operation.
21    #[error("permission denied: {0}")]
22    Permission(String),
23
24    /// Requested resource not found.
25    #[error("not found: {0}")]
26    NotFound(String),
27}
28
29impl ToolError {
30    /// Create an invalid input error.
31    pub fn invalid_input<S: ToString>(s: S) -> Self {
32        ToolError::InvalidInput(s.to_string())
33    }
34
35    /// Create an internal error.
36    pub fn internal<S: ToString>(s: S) -> Self {
37        ToolError::Internal(s.to_string())
38    }
39
40    /// Create an external service error.
41    pub fn external<S: ToString>(s: S) -> Self {
42        ToolError::External(s.to_string())
43    }
44
45    /// Create a not found error.
46    pub fn not_found<S: ToString>(s: S) -> Self {
47        ToolError::NotFound(s.to_string())
48    }
49
50    /// Create a permission denied error.
51    pub fn permission<S: ToString>(s: S) -> Self {
52        ToolError::Permission(s.to_string())
53    }
54}