hopr_protocol_hopr/
errors.rs1use hopr_api::{
2 Address,
3 types::{
4 crypto::{prelude::HalfKeyChallenge, types::OffchainPublicKey},
5 internal::prelude::ChannelId,
6 primitive::balance::HoprBalance,
7 },
8};
9use hopr_crypto_packet::errors::TicketValidationError;
10use thiserror::Error;
11
12#[derive(Debug, strum::EnumIs, strum::EnumTryAs, Error)]
14pub enum IncomingPacketError<E: std::error::Error> {
15 #[error("packet is not decodable: {0}")]
19 Undecodable(E),
20 #[error("packet from {0} decodable, but cannot be processed: {1}")]
24 ProcessingError(Box<OffchainPublicKey>, E),
25 #[error("packet from {0} is decodable, but the ticket is invalid: {1}")]
27 InvalidTicket(Box<OffchainPublicKey>, TicketValidationError),
28 #[error("packet from {0} is a replay")]
37 Replay(Box<OffchainPublicKey>),
38}
39
40impl<E: std::error::Error> IncomingPacketError<E> {
41 pub fn undecodable<Err: Into<E>>(error: Err) -> Self {
43 Self::Undecodable(error.into())
44 }
45}
46
47#[derive(Error, Debug, strum::EnumIs)]
48pub enum HoprProtocolError {
49 #[error("packet is in invalid state: {0}")]
50 InvalidState(&'static str),
51
52 #[error("cannot decode the sender address of the packet")]
53 InvalidSender,
54
55 #[error("failed to resolve chain key or packet key")]
56 KeyNotFound,
57
58 #[error("channel {0} does not have at least {1} to create a ticket")]
59 OutOfFunds(ChannelId, HoprBalance),
60
61 #[error("failed to find channel {0} -> {1}")]
62 ChannelNotFound(Address, Address),
63
64 #[error("could not find unacknowledged ticket for challenge {0}")]
65 UnacknowledgedTicketNotFound(HalfKeyChallenge),
66
67 #[error("ticket index {2} in channel {0} epoch {1} was already accepted")]
70 DuplicateTicketIndex(ChannelId, u32, u64),
71
72 #[error("chain resolver error: {0}")]
73 ResolverError(#[source] anyhow::Error),
74
75 #[error("ticket factory error: {0}")]
76 TicketFactoryError(#[source] anyhow::Error),
77
78 #[error(transparent)]
79 TicketValidationError(#[from] TicketValidationError),
80
81 #[error(transparent)]
82 CoreTypesError(#[from] hopr_api::types::internal::errors::CoreTypesError),
83
84 #[error(transparent)]
85 PacketError(#[from] hopr_crypto_packet::errors::PacketError),
86
87 #[error(transparent)]
88 GeneralError(#[from] hopr_api::types::primitive::errors::GeneralError),
89
90 #[error("rayon thread pool queue full: {0}")]
91 SpawnError(#[from] hopr_utils::parallelize::cpu::SpawnError),
92}
93
94impl HoprProtocolError {
95 pub fn resolver<E: Into<anyhow::Error>>(e: E) -> Self {
97 Self::ResolverError(e.into())
98 }
99
100 pub fn ticket_factory<E: Into<anyhow::Error>>(e: E) -> Self {
102 Self::TicketFactoryError(e.into())
103 }
104}