Skip to main content

hopr_transport/
errors.rs

1use hopr_crypto_packet::errors::PacketError;
2pub use hopr_transport_probe::errors::ProbeError;
3
4/// Errors from the network peer store.
5#[derive(thiserror::Error, Debug)]
6pub enum NetworkError {
7    #[error("performing an operation on own PeerId")]
8    DisallowedOperationOnOwnPeerIdError,
9}
10use hopr_ticket_manager::TicketManagerError;
11use hopr_transport_session::errors::TransportSessionError;
12use thiserror::Error;
13
14pub use crate::protocol::errors::ProtocolError;
15
16/// Errors produced by the crate.
17#[derive(Error, Debug)]
18pub enum HoprTransportError {
19    #[error("API error: {0}")]
20    Api(String),
21
22    #[error("General error: {0}")]
23    General(#[from] hopr_api::types::primitive::errors::GeneralError),
24
25    #[error("Path error: {0}")]
26    Path(#[from] hopr_api::types::internal::errors::PathError),
27
28    #[error("Protocol error: {0}")]
29    Protocol(#[from] ProtocolError),
30
31    #[error("Probe error: {0}")]
32    Probe(#[from] ProbeError),
33
34    #[error("Transport session error: {0}")]
35    Session(#[from] TransportSessionError),
36
37    #[error("Ticket manager error: {0}")]
38    TicketManager(#[from] TicketManagerError),
39
40    #[error("Packet error: {0}")]
41    Packet(#[from] PacketError),
42
43    #[error("Type error: {0}")]
44    Types(#[from] hopr_api::types::internal::errors::CoreTypesError),
45
46    #[error("Network monitoring error: {0}")]
47    NetworkError(#[from] NetworkError),
48
49    #[error(transparent)]
50    ApplicationLayerError(#[from] hopr_protocol_app::errors::ApplicationLayerError),
51
52    #[error("tag allocator error: {0}")]
53    TagAllocator(#[from] hopr_transport_tag_allocator::TagAllocatorError),
54
55    #[error("chain error: {0}")]
56    Chain(#[source] anyhow::Error),
57
58    #[error("unspecified error: {0}")]
59    Other(#[source] anyhow::Error),
60}
61
62impl HoprTransportError {
63    pub fn chain<E: Into<anyhow::Error>>(e: E) -> Self {
64        Self::Chain(e.into())
65    }
66
67    pub fn other<E: Into<anyhow::Error>>(e: E) -> Self {
68        Self::Other(e.into())
69    }
70}
71
72/// Result produced by the crate, uses the [HoprTransportError] as the error type.
73pub type Result<T> = core::result::Result<T, HoprTransportError>;