hopr_transport_session/
errors.rs1use thiserror::Error;
2
3#[derive(Error, Debug)]
5pub enum TransportSessionError {
6 #[error("session operation timed out")]
7 Timeout,
8
9 #[error("unparseable session id")]
10 InvalidSessionId,
11
12 #[error("the other party rejected session initiation with error: {0}")]
13 Rejected(hopr_protocol_start::StartErrorReason),
14
15 #[error("received data for an unregistered session")]
16 UnknownData,
17
18 #[error("packet sending error: {0}")]
19 PacketSendingError(anyhow::Error),
20
21 #[error(transparent)]
22 StartProtocolError(#[from] hopr_protocol_start::errors::StartProtocolError),
23
24 #[error(transparent)]
25 SessionProtocolError(#[from] hopr_protocol_session::errors::SessionError),
26
27 #[error(transparent)]
28 Manager(#[from] SessionManagerError),
29
30 #[error(transparent)]
31 Network(#[from] hopr_network_types::errors::NetworkTypeError),
32
33 #[error("session is closed")]
34 Closed,
35}
36
37impl TransportSessionError {
38 pub fn packet_sending<E: Into<anyhow::Error>>(e: E) -> Self {
39 Self::PacketSendingError(e.into())
40 }
41}
42
43impl From<TransportSessionError> for std::io::Error {
44 fn from(error: TransportSessionError) -> Self {
45 std::io::Error::other(error)
46 }
47}
48
49#[derive(Error, Debug)]
50pub enum SessionManagerError {
51 #[error("manager is not started")]
52 NotStarted,
53 #[error("manager is already started")]
54 AlreadyStarted,
55 #[error("all challenge slots are occupied")]
56 NoChallengeSlots,
57 #[error("session with the given id does not exist")]
58 NonExistingSession,
59 #[error("number of sessions exceeds the maximum allowed")]
60 TooManySessions,
61 #[error("loopback sessions are not allowed")]
62 Loopback,
63 #[error(transparent)]
64 Other(anyhow::Error),
65}
66
67impl SessionManagerError {
68 pub fn other<E: Into<anyhow::Error>>(e: E) -> Self {
69 Self::Other(e.into())
70 }
71}
72
73pub type Result<T> = std::result::Result<T, TransportSessionError>;