Skip to main content

kwaai_distributed/
error.rs

1//! Error types for distributed operations
2
3use thiserror::Error;
4
5/// Result type for distributed operations
6pub type DistributedResult<T> = Result<T, DistributedError>;
7
8/// Errors that can occur in distributed operations
9#[derive(Error, Debug)]
10pub enum DistributedError {
11    /// Expert not found
12    #[error("Expert not found: {0}")]
13    ExpertNotFound(String),
14
15    /// Remote call failed
16    #[error("Remote call failed: {0}")]
17    RemoteCallFailed(String),
18
19    /// Timeout
20    #[error("Operation timed out after {0}ms")]
21    Timeout(u64),
22
23    /// No peers available
24    #[error("No peers available for {0}")]
25    NoPeersAvailable(String),
26
27    /// Averaging failed
28    #[error("Averaging failed: {0}")]
29    AveragingFailed(String),
30
31    /// Routing failed
32    #[error("Routing failed: {0}")]
33    RoutingFailed(String),
34
35    /// All retries exhausted
36    #[error("All retries exhausted: {0}")]
37    RetriesExhausted(String),
38
39    /// Network error
40    #[error("Network error: {0}")]
41    NetworkError(String),
42
43    /// Compression error
44    #[error("Compression error: {0}")]
45    CompressionError(String),
46
47    /// Tensor error
48    #[error("Tensor error: {0}")]
49    TensorError(String),
50
51    /// Internal error
52    #[error("Internal error: {0}")]
53    Internal(String),
54}
55
56impl From<kwaai_p2p::P2PError> for DistributedError {
57    fn from(err: kwaai_p2p::P2PError) -> Self {
58        DistributedError::NetworkError(err.to_string())
59    }
60}
61
62impl From<kwaai_compression::CompressionError> for DistributedError {
63    fn from(err: kwaai_compression::CompressionError) -> Self {
64        DistributedError::CompressionError(err.to_string())
65    }
66}
67
68impl From<candle_core::Error> for DistributedError {
69    fn from(err: candle_core::Error) -> Self {
70        DistributedError::TensorError(err.to_string())
71    }
72}