Skip to main content

acktor_ipc/
errors.rs

1//! Error types used by this crate.
2
3use std::io;
4
5use thiserror::Error;
6
7use acktor::{BoxError, RecvError, SendError};
8
9pub use crate::codec::{DecodeError, EncodeError};
10pub use crate::double_map::{KeyConflictError, TryReserveError};
11pub use crate::remote_message::ToRemoteMessageRecipientError;
12
13/// Error type used by [`Node`][crate::node::Node].
14#[derive(Debug, Error)]
15pub enum NodeError {
16    #[error("could not connect to the remote endpoint")]
17    ConnectFailed(#[from] io::Error),
18
19    #[error("could not create a new session")]
20    CreateSessionFailed(#[source] BoxError),
21
22    #[error("could not find the session {0}")]
23    SessionNotFound(String),
24
25    #[error("could not create the remote actor")]
26    CreateRemoteActorFailed(#[source] SessionError),
27
28    #[error("could not find the actor in the remote process")]
29    RemoteActorNotFound(#[source] SessionError),
30
31    #[error("could not send message")]
32    SendError(#[source] BoxError),
33
34    #[error("could not receive message")]
35    RecvError(#[from] RecvError),
36}
37
38impl<T> From<SendError<T>> for NodeError
39where
40    T: Send + Sync + 'static,
41{
42    fn from(source: SendError<T>) -> Self {
43        Self::SendError(source.into())
44    }
45}
46
47/// Error type used by [`Node`][crate::node::Node] to represent session related errors.
48#[derive(Debug, Error)]
49pub enum SessionError {
50    #[error("could not encode the outbound remote message")]
51    EncodeError(#[from] EncodeError),
52
53    #[error("could not decode the inbound remote message")]
54    DecodeError(#[from] DecodeError),
55
56    #[error("could not send the outbound remote message to the remote node")]
57    SendOutboundMessageFailed(#[source] io::Error),
58
59    #[error("could not forward the inbound remote message to any actor")]
60    ForwardInboundMessageFailed(#[source] BoxError),
61
62    #[error("invalid node message response tag: {0}")]
63    InvalidNodeMsgResTxTag(u64),
64
65    #[error("could not forward the node message response to the original sender")]
66    ForwardNodeMsgResFailed,
67
68    #[error("invalid actor message response tag: {0}")]
69    InvalidActorMsgResTxTag(u64),
70
71    #[error("could not forward the actor message response")]
72    ForwardActorMessageResFailed,
73
74    #[error("could not create the actor on behalf of the remote peer")]
75    RemoteActorFactoryError(#[source] BoxError),
76
77    #[error("could not find actor {0} in the current process")]
78    ActorNotFound(String),
79
80    #[error("could not handle inbound remote message")]
81    HandleInboundMessageFailed(#[source] BoxError),
82
83    #[error("remote actor returned an error:{0}")]
84    RemotePeerError(String),
85
86    #[error(transparent)]
87    IoError(io::Error),
88
89    #[error("could not send message")]
90    SendError(#[source] BoxError),
91
92    #[error("could not receive message")]
93    RecvError(#[from] RecvError),
94}
95
96impl<T> From<SendError<T>> for SessionError
97where
98    T: Send + Sync + 'static,
99{
100    fn from(source: SendError<T>) -> Self {
101        Self::SendError(source.into())
102    }
103}