hopr_chain_connector/
errors.rs1use blokli_client::errors::{ErrorKind, TrackingErrorKind};
2use hopr_api::chain::HoprKeyIdent;
3use hopr_internal_types::prelude::ChannelId;
4use thiserror::Error;
5
6#[derive(Debug, Error)]
7pub enum ConnectorError {
8 #[error("invalid arguments: {0}")]
9 InvalidArguments(&'static str),
10
11 #[error("invalid state: {0}")]
12 InvalidState(&'static str),
13
14 #[error("account {0} does not exist")]
15 AccountDoesNotExist(HoprKeyIdent),
16
17 #[error("channel {0} does not exist")]
18 ChannelDoesNotExist(ChannelId),
19
20 #[error("ticket is invalid or does not match the channel")]
21 InvalidTicket,
22
23 #[error("channel {0} is closed")]
24 ChannelClosed(ChannelId),
25
26 #[error("type conversion error: {0}")]
27 TypeConversion(String),
28
29 #[error("timeout while waiting for the graph to be synced")]
30 ConnectionTimeout,
31
32 #[error("backend error: {0}")]
33 BackendError(anyhow::Error),
34
35 #[error(transparent)]
36 CacheError(#[from] std::sync::Arc<Self>),
37
38 #[error(transparent)]
39 ClientError(#[from] blokli_client::errors::BlokliClientError),
40
41 #[error(transparent)]
42 GeneralError(#[from] hopr_primitive_types::errors::GeneralError),
43
44 #[error(transparent)]
45 ChainTypesError(#[from] hopr_chain_types::errors::ChainTypesError),
46
47 #[error(transparent)]
48 CoreTypesError(#[from] hopr_internal_types::errors::CoreTypesError),
49
50 #[error(transparent)]
51 IoError(#[from] std::io::Error),
52
53 #[error("undefined error: {0}")]
54 OtherError(anyhow::Error),
55}
56
57impl ConnectorError {
58 pub fn as_transaction_rejection_error(&self) -> Option<&TrackingErrorKind> {
61 match self {
62 ConnectorError::ClientError(client_error) => match client_error.kind() {
63 ErrorKind::TrackingError(e @ TrackingErrorKind::Reverted)
64 | ErrorKind::TrackingError(e @ TrackingErrorKind::ValidationFailed) => Some(e),
65 _ => None,
66 },
67 _ => None,
68 }
69 }
70}
71
72pub type Result<T> = std::result::Result<T, ConnectorError>;