1use sea_orm::TransactionError;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum DbError {
6 #[error("alias not found: {0}")]
7 AliasNotFound(String),
8
9 #[error("re-aliasing self is not allowed")]
10 ReAliasingSelfNotAllowed,
11
12 #[error("alias or peer id already exists")]
13 AliasOrPeerIdAlreadyExists,
14
15 #[error("transaction error: {0}")]
16 TransactionError(Box<dyn std::error::Error + Send + Sync>),
17
18 #[error("logical error: {0}")]
19 LogicalError(String),
20
21 #[error(transparent)]
22 BackendError(#[from] sea_orm::DbErr),
23}
24
25impl<E: std::error::Error + Send + Sync + 'static> From<TransactionError<E>> for DbError {
26 fn from(value: TransactionError<E>) -> Self {
27 match value {
28 TransactionError::Connection(e) => Self::BackendError(e),
29 TransactionError::Transaction(e) => Self::TransactionError(Box::new(e)),
30 }
31 }
32}
33
34pub type Result<T> = std::result::Result<T, DbError>;