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