1use std::sync::Arc;
2
3use hopr_crypto_packet::errors::TicketValidationError;
4use hopr_crypto_types::{prelude::CryptoError, types::Hash};
5use hopr_db_entity::errors::DbEntityError;
6use hopr_internal_types::{errors::CoreTypesError, tickets::Ticket};
7use sea_orm::TransactionError;
8use thiserror::Error;
9
10#[derive(Debug, Error)]
11pub enum DbSqlError {
12 #[error("failed to construct the database: {0}")]
13 Construction(String),
14
15 #[error("log status not found")]
16 MissingLogStatus,
17
18 #[error("log not found")]
19 MissingLog,
20
21 #[error("list of logs is empty")]
22 EmptyLogsList,
23
24 #[error("log status could not be updated")]
25 UpdateLogStatusError,
26
27 #[error("account entry for announcement not found")]
28 MissingAccount,
29
30 #[error("channel not found: {0}")]
31 ChannelNotFound(Hash),
32
33 #[error("can't edit a corrupted channel: {0}")]
34 CorruptedChannelEntry(Hash),
35
36 #[error("missing fixed entry in table {0}")]
37 MissingFixedTableEntry(String),
38
39 #[error("ticket aggregation error: {0}")]
40 TicketAggregationError(String),
41
42 #[error("ticket validation error for {}: {}", .0.0, .0.1)]
43 TicketValidationError(Box<(Ticket, String)>),
44
45 #[error("transaction error: {0}")]
46 TransactionError(Box<dyn std::error::Error + Send + Sync>),
47
48 #[error("error while decoding db entity")]
49 DecodingError,
50
51 #[error("logical error: {0}")]
52 LogicalError(String),
53
54 #[error("ack validation error: {0}")]
55 AcknowledgementValidationError(String),
56
57 #[error(transparent)]
58 BackendError(#[from] sea_orm::DbErr),
59
60 #[error(transparent)]
61 CoreTypesError(#[from] CoreTypesError),
62
63 #[error(transparent)]
64 CryptoError(#[from] CryptoError),
65
66 #[error(transparent)]
67 EntityError(#[from] DbEntityError),
68
69 #[error("error while inserting into cache: {0}")]
70 CacheError(#[from] Arc<Self>),
71
72 #[error(transparent)]
73 NonSpecificError(#[from] hopr_primitive_types::errors::GeneralError),
74
75 #[error(transparent)]
76 ApiError(#[from] hopr_db_api::errors::DbError),
77}
78
79impl From<TicketValidationError> for DbSqlError {
80 fn from(value: TicketValidationError) -> Self {
81 DbSqlError::TicketValidationError(Box::new((*value.ticket, value.reason)))
82 }
83}
84
85impl From<DbSqlError> for hopr_db_api::errors::DbError {
86 fn from(value: DbSqlError) -> Self {
87 hopr_db_api::errors::DbError::General(value.to_string())
88 }
89}
90
91impl<E: std::error::Error + Send + Sync + 'static> From<TransactionError<E>> for DbSqlError {
92 fn from(value: TransactionError<E>) -> Self {
93 match value {
94 TransactionError::Connection(e) => Self::BackendError(e),
95 TransactionError::Transaction(e) => Self::TransactionError(e.into()),
96 }
97 }
98}
99
100pub type Result<T> = std::result::Result<T, DbSqlError>;