Skip to main content

mdcs_sdk/
error.rs

1//! Error types for the MDCS SDK.
2
3use std::fmt;
4
5/// Error type for SDK operations.
6#[derive(Debug)]
7pub enum SdkError {
8    /// Document not found.
9    DocumentNotFound(String),
10    /// Peer not found.
11    PeerNotFound(String),
12    /// Connection failed.
13    ConnectionFailed(String),
14    /// Sync error.
15    SyncError(String),
16    /// Network error.
17    NetworkError(String),
18    /// Serialization error.
19    SerializationError(String),
20    /// Internal error.
21    Internal(String),
22}
23
24impl fmt::Display for SdkError {
25    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26        match self {
27            SdkError::DocumentNotFound(id) => write!(f, "Document not found: {}", id),
28            SdkError::PeerNotFound(id) => write!(f, "Peer not found: {}", id),
29            SdkError::ConnectionFailed(e) => write!(f, "Connection failed: {}", e),
30            SdkError::SyncError(e) => write!(f, "Sync error: {}", e),
31            SdkError::NetworkError(e) => write!(f, "Network error: {}", e),
32            SdkError::SerializationError(e) => write!(f, "Serialization error: {}", e),
33            SdkError::Internal(e) => write!(f, "Internal error: {}", e),
34        }
35    }
36}
37
38impl std::error::Error for SdkError {}
39
40/// Result type for SDK operations.
41pub type Result<T> = std::result::Result<T, SdkError>;