Skip to main content

emergent_client/
error.rs

1//! Error types for the Emergent client library.
2
3use acton_reactive::ipc::IpcError;
4use thiserror::Error;
5
6/// Client errors.
7#[derive(Debug, Error)]
8pub enum ClientError {
9    /// Connection failed.
10    #[error("Failed to connect to engine: {0}")]
11    ConnectionFailed(String),
12
13    /// Socket not found.
14    #[error("Engine socket not found at: {0}")]
15    SocketNotFound(String),
16
17    /// I/O error during communication.
18    #[error("Communication error: {0}")]
19    IoError(#[from] std::io::Error),
20
21    /// IPC error.
22    #[error("IPC error: {0}")]
23    IpcError(String),
24
25    /// Serialization error.
26    #[error("Serialization error: {0}")]
27    SerializationError(String),
28
29    /// Subscription failed.
30    #[error("Subscription failed: {0}")]
31    SubscriptionFailed(String),
32
33    /// Publish failed.
34    #[error("Publish failed: {0}")]
35    PublishFailed(String),
36
37    /// Discovery failed.
38    #[error("Discovery failed: {0}")]
39    DiscoveryFailed(String),
40
41    /// Request timed out.
42    #[error("Request timed out")]
43    Timeout,
44
45    /// Engine returned an error.
46    #[error("Engine error: {0}")]
47    EngineError(String),
48
49    /// Protocol error.
50    #[error("Protocol error: {0}")]
51    ProtocolError(String),
52}
53
54impl From<IpcError> for ClientError {
55    fn from(e: IpcError) -> Self {
56        ClientError::IpcError(e.to_string())
57    }
58}
59
60impl From<serde_json::Error> for ClientError {
61    fn from(e: serde_json::Error) -> Self {
62        ClientError::SerializationError(e.to_string())
63    }
64}
65
66impl From<rmp_serde::encode::Error> for ClientError {
67    fn from(e: rmp_serde::encode::Error) -> Self {
68        ClientError::SerializationError(e.to_string())
69    }
70}
71
72impl From<rmp_serde::decode::Error> for ClientError {
73    fn from(e: rmp_serde::decode::Error) -> Self {
74        ClientError::SerializationError(e.to_string())
75    }
76}