hehe_tools/
error.rs

1use hehe_core::error::Error as CoreError;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum ToolError {
6    #[error("Tool not found: {0}")]
7    NotFound(String),
8
9    #[error("Tool already registered: {0}")]
10    AlreadyRegistered(String),
11
12    #[error("Invalid input: {0}")]
13    InvalidInput(String),
14
15    #[error("Execution failed: {tool} - {message}")]
16    ExecutionFailed { tool: String, message: String },
17
18    #[error("Permission denied: {0}")]
19    PermissionDenied(String),
20
21    #[error("Timeout after {0}ms")]
22    Timeout(u64),
23
24    #[error("Cancelled")]
25    Cancelled,
26
27    #[error("IO error: {0}")]
28    Io(#[from] std::io::Error),
29
30    #[error("JSON error: {0}")]
31    Json(#[from] serde_json::Error),
32
33    #[error(transparent)]
34    Core(#[from] CoreError),
35
36    #[cfg(feature = "http")]
37    #[error("HTTP error: {0}")]
38    Http(#[from] reqwest::Error),
39}
40
41pub type Result<T> = std::result::Result<T, ToolError>;
42
43impl ToolError {
44    pub fn not_found(name: impl Into<String>) -> Self {
45        Self::NotFound(name.into())
46    }
47
48    pub fn invalid_input(msg: impl Into<String>) -> Self {
49        Self::InvalidInput(msg.into())
50    }
51
52    pub fn execution_failed(tool: impl Into<String>, message: impl Into<String>) -> Self {
53        Self::ExecutionFailed {
54            tool: tool.into(),
55            message: message.into(),
56        }
57    }
58
59    pub fn permission_denied(msg: impl Into<String>) -> Self {
60        Self::PermissionDenied(msg.into())
61    }
62}