language_barrier_core/
error.rs

1use thiserror::Error;
2
3/// Errors that can occur when working with tools
4#[derive(Error, Debug)]
5pub enum ToolError {
6    /// Tool with the specified name was not found in the registry
7    #[error("Tool not found: {0}")]
8    NotFound(String),
9
10    /// Error generating JSON schema for tool
11    #[error("Failed to generate schema for tool '{0}': {1}")]
12    SchemaGenerationError(String, serde_json::Error),
13
14    /// Error parsing arguments for tool
15    #[error("Failed to parse arguments for tool '{0}': {1}")]
16    ArgumentParsingError(String, serde_json::Error),
17
18    /// Invalid arguments for tool
19    #[error("Invalid arguments for tool: {0}")]
20    InvalidArguments(String),
21
22    /// Tool execution encountered an error
23    #[error("Tool execution failed: {0}")]
24    ExecutionError(String),
25
26    /// Expected output type did not match actual output type
27    #[error("Type mismatch after execution for tool '{0}': Expected different output type")]
28    OutputTypeMismatch(String),
29}
30
31/// Represents errors that can occur in the language-barrier library
32#[derive(Error, Debug)]
33pub enum Error {
34    /// Error during serialization or deserialization
35    #[error("Serialization error: {0}")]
36    Serialization(#[from] serde_json::Error),
37
38    /// Error during HTTP request
39    #[error("HTTP request error: {0}")]
40    Request(#[from] reqwest::Error),
41
42    #[error("Couldn't parse base url")]
43    BaseUrlError(#[from] url::ParseError),
44
45    /// Rate limit exceeded
46    #[error("Rate limit exceeded: {0}")]
47    RateLimit(String),
48
49    /// Authentication error
50    #[error("Authentication error: {0}")]
51    Authentication(String),
52
53    /// Model not supported
54    #[error("Model not supported: {0}")]
55    UnsupportedModel(String),
56
57    /// Provider not available
58    #[error("Provider not available: {0}")]
59    ProviderUnavailable(String),
60
61    /// Context length exceeded
62    #[error("Context length exceeded: {0}")]
63    ContextLengthExceeded(String),
64
65    /// Tool not found
66    #[error("Tool not found: {0}")]
67    ToolNotFound(String),
68
69    /// Invalid tool parameter
70    #[error("Invalid tool parameter: {0}")]
71    InvalidToolParameter(String),
72    
73    /// Invalid tool arguments
74    #[error("Invalid tool arguments: {0}")]
75    InvalidToolArguments(String),
76
77    /// Tool execution error
78    #[error("Tool execution error: {0}")]
79    ToolExecutionError(String),
80    
81    /// Tool-specific error
82    #[error("Tool error: {0}")]
83    Tool(#[from] ToolError),
84
85    /// Provider feature not supported
86    #[error("Provider feature not supported: {0}")]
87    ProviderFeatureNotSupported(String),
88
89    /// Generic error
90    #[error("{0}")]
91    Other(String),
92}
93
94/// A Result type that uses our Error type
95pub type Result<T> = std::result::Result<T, Error>;