cala_ledger/ledger/
error.rs1use sqlx::error::DatabaseError;
2use thiserror::Error;
3
4use crate::{
5 account::error::AccountError, account_set::error::AccountSetError,
6 balance::error::BalanceError, entry::error::EntryError, journal::error::JournalError,
7 outbox::server::error::OutboxServerError, transaction::error::TransactionError,
8 tx_template::error::TxTemplateError, velocity::error::VelocityError,
9};
10
11#[derive(Error, Debug)]
12pub enum LedgerError {
13 #[error("LedgerError - Sqlx: {0}")]
14 Sqlx(sqlx::Error),
15 #[error("LedgerError - DuplicateKey: {0}")]
16 DuplicateKey(Box<dyn DatabaseError>),
17 #[error("LedgerError - Migrate: {0}")]
18 SqlxMigrate(#[from] sqlx::migrate::MigrateError),
19 #[error("LedgerError - Config: {0}")]
20 ConfigError(String),
21 #[error("LedgerError - OutboxServer: {0}")]
22 OutboxServer(#[from] OutboxServerError),
23 #[error("LedgerError - AccountError: {0}")]
24 AccountError(#[from] AccountError),
25 #[error("LedgerError - AccountSetError: {0}")]
26 AccountSetError(#[from] AccountSetError),
27 #[error("LedgerError - JournalError: {0}")]
28 JournalError(#[from] JournalError),
29 #[error("LedgerError - TxTemplateError: {0}")]
30 TxTemplateError(#[from] TxTemplateError),
31 #[error("LedgerError - TransactionError: {0}")]
32 TransactionError(#[from] TransactionError),
33 #[error("LedgerError - EntryError: {0}")]
34 EntryError(#[from] EntryError),
35 #[error("LedgerError - BalanceError: {0}")]
36 BalanceError(#[from] BalanceError),
37 #[error("LedgerError - VelocityError: {0}")]
38 VelocityError(#[from] VelocityError),
39}
40
41impl From<sqlx::Error> for LedgerError {
42 fn from(e: sqlx::Error) -> Self {
43 match e {
44 sqlx::Error::Database(err) if err.message().contains("duplicate key") => {
45 LedgerError::DuplicateKey(err)
46 }
47 e => LedgerError::Sqlx(e),
48 }
49 }
50}