mockforge_collab/
error.rs

1//! Error types for collaboration features
2
3/// Result type for collaboration operations
4pub type Result<T> = std::result::Result<T, CollabError>;
5
6/// Errors that can occur during collaboration operations
7#[derive(Debug, thiserror::Error)]
8pub enum CollabError {
9    /// Authentication failed
10    #[error("Authentication failed: {0}")]
11    AuthenticationFailed(String),
12
13    /// Authorization failed (insufficient permissions)
14    #[error("Authorization failed: {0}")]
15    AuthorizationFailed(String),
16
17    /// Workspace not found
18    #[error("Workspace not found: {0}")]
19    WorkspaceNotFound(String),
20
21    /// User not found
22    #[error("User not found: {0}")]
23    UserNotFound(String),
24
25    /// Conflict detected
26    #[error("Conflict detected: {0}")]
27    ConflictDetected(String),
28
29    /// Sync error
30    #[error("Sync error: {0}")]
31    SyncError(String),
32
33    /// Database error
34    #[error("Database error: {0}")]
35    DatabaseError(String),
36
37    /// WebSocket error
38    #[error("WebSocket error: {0}")]
39    WebSocketError(String),
40
41    /// Serialization error
42    #[error("Serialization error: {0}")]
43    SerializationError(String),
44
45    /// Invalid input
46    #[error("Invalid input: {0}")]
47    InvalidInput(String),
48
49    /// Resource already exists
50    #[error("Resource already exists: {0}")]
51    AlreadyExists(String),
52
53    /// Operation timeout
54    #[error("Operation timeout: {0}")]
55    Timeout(String),
56
57    /// Connection error
58    #[error("Connection error: {0}")]
59    ConnectionError(String),
60
61    /// Version mismatch
62    #[error("Version mismatch: expected {expected}, got {actual}")]
63    VersionMismatch { expected: u64, actual: u64 },
64
65    /// Internal error
66    #[error("Internal error: {0}")]
67    Internal(String),
68}
69
70impl From<sqlx::Error> for CollabError {
71    fn from(err: sqlx::Error) -> Self {
72        CollabError::DatabaseError(err.to_string())
73    }
74}
75
76impl From<serde_json::Error> for CollabError {
77    fn from(err: serde_json::Error) -> Self {
78        CollabError::SerializationError(err.to_string())
79    }
80}
81
82impl From<tokio::time::error::Elapsed> for CollabError {
83    fn from(err: tokio::time::error::Elapsed) -> Self {
84        CollabError::Timeout(err.to_string())
85    }
86}
87
88impl From<sqlx::migrate::MigrateError> for CollabError {
89    fn from(err: sqlx::migrate::MigrateError) -> Self {
90        CollabError::DatabaseError(err.to_string())
91    }
92}