hopr_chain_connector/
errors.rs1use blokli_client::errors::{ErrorKind, TrackingErrorKind};
2use hopr_internal_types::prelude::ChannelId;
3use hopr_primitive_types::prelude::Address;
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("blokli server is not healthy")]
15 ServerNotHealthy,
16
17 #[error("account {0} does not exist")]
18 AccountDoesNotExist(String),
19
20 #[error("safe {0} does not exist")]
21 SafeDoesNotExist(Address),
22
23 #[error("channel {0} does not exist")]
24 ChannelDoesNotExist(ChannelId),
25
26 #[error("ticket is invalid or does not match the channel")]
27 InvalidTicket,
28
29 #[error("channel {0} is closed")]
30 ChannelClosed(ChannelId),
31
32 #[error("type conversion error: {0}")]
33 TypeConversion(String),
34
35 #[error("timeout while waiting for the graph to be synced")]
36 ConnectionTimeout,
37
38 #[error("backend error: {0}")]
39 BackendError(#[source] anyhow::Error),
40
41 #[error(transparent)]
42 CacheError(#[from] std::sync::Arc<Self>),
43
44 #[error(transparent)]
45 ClientError(#[from] blokli_client::errors::BlokliClientError),
46
47 #[error(transparent)]
48 GeneralError(#[from] hopr_primitive_types::errors::GeneralError),
49
50 #[error(transparent)]
51 ChainTypesError(#[from] hopr_chain_types::errors::ChainTypesError),
52
53 #[error(transparent)]
54 CoreTypesError(#[from] hopr_internal_types::errors::CoreTypesError),
55
56 #[error(transparent)]
57 IoError(#[from] std::io::Error),
58
59 #[error("undefined error: {0}")]
60 OtherError(#[source] anyhow::Error),
61}
62
63impl ConnectorError {
64 pub fn as_transaction_rejection_error(&self) -> Option<&TrackingErrorKind> {
67 match self {
68 ConnectorError::ClientError(client_error) => match client_error.kind() {
69 ErrorKind::TrackingError(e @ TrackingErrorKind::Reverted)
70 | ErrorKind::TrackingError(e @ TrackingErrorKind::ValidationFailed) => Some(e),
71 _ => None,
72 },
73 _ => None,
74 }
75 }
76}
77
78pub type Result<T> = std::result::Result<T, ConnectorError>;