hopr_crypto_packet/
errors.rs1use hopr_crypto_types::errors::CryptoError;
2use hopr_internal_types::errors::CoreTypesError;
3use hopr_internal_types::prelude::Ticket;
4use hopr_primitive_types::errors::GeneralError;
5use std::fmt::{Debug, Display, Formatter};
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 is in invalid state")]
17 InvalidPacketState,
18
19 #[error("packet tag already present, possible replay")]
20 TagReplay,
21
22 #[error("could not find channel to {0}")]
23 ChannelNotFound(String),
24
25 #[error("ticket validation failed, packet dropped: {0}")]
26 TicketValidation(TicketValidationError),
27
28 #[error("received invalid acknowledgement: {0}")]
29 AcknowledgementValidation(String),
30
31 #[error("Proof of Relay challenge could not be verified")]
32 PoRVerificationError,
33
34 #[error("channel {0} is out of funds")]
35 OutOfFunds(String),
36
37 #[error("logic error during packet processing: {0}")]
38 LogicError(String),
39
40 #[error("tx queue is full, retry later")]
41 Retry,
42
43 #[error("underlying transport error while sending packet: {0}")]
44 TransportError(String),
45
46 #[error("path position from the packet header mismatched with the path position in ticket")]
47 PathPositionMismatch,
48
49 #[error("no channel domain_separator tag found")]
50 MissingDomainSeparator,
51
52 #[error(transparent)]
53 CryptographicError(#[from] CryptoError),
54
55 #[error(transparent)]
56 CoreTypesError(#[from] CoreTypesError),
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}