hopr_crypto_packet/
errors.rs1use std::fmt::{Debug, Display, Formatter};
2
3use hopr_crypto_types::errors::CryptoError;
4use hopr_internal_types::{errors::CoreTypesError, prelude::Ticket};
5use hopr_primitive_types::errors::GeneralError;
6use thiserror::Error;
7
8#[derive(Error, Debug)]
9pub enum PacketError {
10 #[error("failed to decode packet: {0}")]
11 PacketDecodingError(String),
12
13 #[error("failed to construct packet: {0}")]
14 PacketConstructionError(String),
15
16 #[error("packet tag already present, possible replay")]
17 TagReplay,
18
19 #[error("could not find channel to {0}")]
20 ChannelNotFound(String),
21
22 #[error("ticket validation failed, packet dropped: {0}")]
23 TicketValidation(TicketValidationError),
24
25 #[error("received invalid acknowledgement: {0}")]
26 AcknowledgementValidation(String),
27
28 #[error("Proof of Relay challenge could not be verified")]
29 PoRVerificationError,
30
31 #[error("channel {0} is out of funds")]
32 OutOfFunds(String),
33
34 #[error("logic error during packet processing: {0}")]
35 LogicError(String),
36
37 #[error("tx queue is full, retry later")]
38 Retry,
39
40 #[error("underlying transport error while sending packet: {0}")]
41 TransportError(String),
42
43 #[error("path position from the packet header mismatched with the path position in ticket")]
44 PathPositionMismatch,
45
46 #[error("no channel domain_separator tag found")]
47 MissingDomainSeparator,
48
49 #[error(transparent)]
50 CryptographicError(#[from] CryptoError),
51
52 #[error(transparent)]
53 CoreTypesError(#[from] CoreTypesError),
54
55 #[error(transparent)]
56 SphinxError(#[from] hopr_crypto_sphinx::errors::SphinxError),
57
58 #[error(transparent)]
59 Other(#[from] GeneralError),
60}
61
62pub type Result<T> = std::result::Result<T, PacketError>;
63
64#[derive(Debug, Clone)]
66pub struct TicketValidationError {
67 pub reason: String,
69 pub ticket: Box<Ticket>,
71}
72
73impl Display for TicketValidationError {
74 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
75 write!(f, "{}", self.reason)
76 }
77}