Skip to main content

commy_sdk_rust/
error.rs

1//! Error types for Commy client SDK
2
3use thiserror::Error;
4
5/// Result type for Commy client operations
6pub type Result<T> = std::result::Result<T, CommyError>;
7
8/// Errors that can occur when using the Commy client SDK
9#[derive(Error, Debug)]
10pub enum CommyError {
11    /// WebSocket connection error
12    #[error("WebSocket error: {0}")]
13    WebSocketError(String),
14
15    /// Connection lost or disconnected
16    #[error("Connection lost: {0}")]
17    ConnectionLost(String),
18
19    /// Authentication failed
20    #[error("Authentication failed: {0}")]
21    AuthenticationFailed(String),
22
23    /// Unauthorized - invalid credentials
24    #[error("Unauthorized: {0}")]
25    Unauthorized(String),
26
27    /// Resource not found
28    #[error("Not found: {0}")]
29    NotFound(String),
30
31    /// Service not found
32    #[error("Service not found: {0}")]
33    ServiceNotFound(String),
34
35    /// Tenant not found
36    #[error("Tenant not found: {0}")]
37    TenantNotFound(String),
38
39    /// Resource already exists
40    #[error("Already exists: {0}")]
41    AlreadyExists(String),
42
43    /// Permission denied
44    #[error("Permission denied: {0}")]
45    PermissionDenied(String),
46
47    /// Invalid request parameters
48    #[error("Invalid request: {0}")]
49    InvalidRequest(String),
50
51    /// Invalid message format
52    #[error("Invalid message format: {0}")]
53    InvalidMessage(String),
54
55    /// Serialization error
56    #[error("Serialization error: {0}")]
57    SerializationError(#[from] serde_json::Error),
58
59    /// MessagePack error
60    #[error("MessagePack error: {0}")]
61    MessagePackError(#[from] rmp_serde::encode::Error),
62
63    /// MessagePack decode error
64    #[error("MessagePack decode error: {0}")]
65    MessagePackDecodeError(#[from] rmp_serde::decode::Error),
66
67    /// Operation timeout
68    #[error("Operation timeout")]
69    Timeout,
70
71    /// Channel send error
72    #[error("Channel error: {0}")]
73    ChannelError(String),
74
75    /// Invalid state
76    #[error("Invalid state: {0}")]
77    InvalidState(String),
78
79    /// Memory mapping error
80    #[error("Memory mapping error: {0}")]
81    MemoryMappingError(String),
82
83    /// File I/O error
84    #[error("File I/O error: {0}")]
85    FileError(#[from] std::io::Error),
86
87    /// File watcher error
88    #[error("File watcher error: {0}")]
89    WatcherError(String),
90
91    /// Variable not found in file
92    #[error("Variable not found: {0}")]
93    VariableNotFound(String),
94
95    /// Invalid variable offset
96    #[error("Invalid variable offset: {0}")]
97    InvalidOffset(String),
98
99    /// SIMD operation error
100    #[error("SIMD operation error: {0}")]
101    SimdError(String),
102
103    /// Generic error
104    #[error("{0}")]
105    Other(String),
106}
107
108impl From<tokio_tungstenite::tungstenite::Error> for CommyError {
109    fn from(err: tokio_tungstenite::tungstenite::Error) -> Self {
110        CommyError::WebSocketError(err.to_string())
111    }
112}