1use serde::{Deserialize, Serialize};
2use thiserror::Error;
3
4#[derive(Error, Debug, Clone, Serialize, Deserialize)]
5pub enum ToolError {
6 #[error("Unknown tool: {0}")]
7 UnknownTool(String),
8
9 #[error("Invalid parameters for {0}: {1}")]
10 InvalidParams(String, String), #[error("{tool_name} failed: {message}")]
13 Execution { tool_name: String, message: String },
14
15 #[error("{0} was cancelled")]
16 Cancelled(String), #[error("{0} timed out")]
19 Timeout(String), #[error("Unexpected error: {0}")]
22 InternalError(String), #[error("File operation failed in {tool_name}: {message}")]
25 Io { tool_name: String, message: String },
26
27 #[error("{0} requires approval to run")]
28 DeniedByUser(String), }
30
31impl ToolError {
32 pub fn execution<T: Into<String>, M: Into<String>>(tool_name: T, message: M) -> Self {
33 ToolError::Execution {
34 tool_name: tool_name.into(),
35 message: message.into(),
36 }
37 }
38
39 pub fn io<T: Into<String>, M: Into<String>>(tool_name: T, message: M) -> Self {
40 ToolError::Io {
41 tool_name: tool_name.into(),
42 message: message.into(),
43 }
44 }
45
46 pub fn invalid_params<T: Into<String>, M: Into<String>>(tool_name: T, message: M) -> Self {
47 ToolError::InvalidParams(tool_name.into(), message.into())
48 }
49}