hopr_transport_session/
errors.rs

1use thiserror::Error;
2
3use crate::initiation::StartErrorReason;
4
5/// Enumeration of errors thrown from this library.
6#[derive(Error, Debug)]
7pub enum TransportSessionError {
8    #[error("connection timed out")]
9    Timeout,
10
11    #[error("incorrect data size")]
12    PayloadSize,
13
14    #[cfg(feature = "serde")]
15    #[error("serializer encoding error: {0}")]
16    SerializerEncoding(#[from] bincode::error::EncodeError),
17
18    #[cfg(feature = "serde")]
19    #[error("serializer decoding error: {0}")]
20    SerializerDecoding(#[from] bincode::error::DecodeError),
21
22    #[error("invalid peer id")]
23    PeerId,
24
25    #[error("impossible transport path")]
26    Path,
27
28    #[error("no surb available for sending reply data")]
29    OutOfSurbs,
30
31    #[error("the other party rejected session initiation with error: {0}")]
32    Rejected(StartErrorReason),
33
34    #[error("received data for an unregistered session")]
35    UnknownData,
36
37    #[error("session establishment protocol error: {0}")]
38    StartProtocolError(String),
39
40    #[error(transparent)]
41    Manager(#[from] SessionManagerError),
42
43    #[error(transparent)]
44    Network(#[from] hopr_network_types::errors::NetworkTypeError),
45
46    #[error("session is closed")]
47    Closed,
48}
49
50#[derive(Error, Debug)]
51pub enum SessionManagerError {
52    #[error("manager is not started")]
53    NotStarted,
54    #[error("manager is already started")]
55    AlreadyStarted,
56    #[error("all challenge slots are occupied")]
57    NoChallengeSlots,
58    #[error("session with the given id does not exist")]
59    NonExistingSession,
60    #[error("loopback sessions are not allowed")]
61    Loopback,
62    #[error("non-specific session manager error: {0}")]
63    Other(String),
64}
65
66pub type Result<T> = std::result::Result<T, TransportSessionError>;