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 transaction::error::TransactionError, tx_template::error::TxTemplateError,
8 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 - AccountError: {0}")]
22 AccountError(#[from] AccountError),
23 #[error("LedgerError - AccountSetError: {0}")]
24 AccountSetError(#[from] AccountSetError),
25 #[error("LedgerError - JournalError: {0}")]
26 JournalError(#[from] JournalError),
27 #[error("LedgerError - TxTemplateError: {0}")]
28 TxTemplateError(#[from] TxTemplateError),
29 #[error("LedgerError - TransactionError: {0}")]
30 TransactionError(#[from] TransactionError),
31 #[error("LedgerError - EntryError: {0}")]
32 EntryError(#[from] EntryError),
33 #[error("LedgerError - BalanceError: {0}")]
34 BalanceError(#[from] BalanceError),
35 #[error("LedgerError - VelocityError: {0}")]
36 VelocityError(#[from] VelocityError),
37}
38
39impl From<sqlx::Error> for LedgerError {
40 fn from(e: sqlx::Error) -> Self {
41 match e {
42 sqlx::Error::Database(err) if err.message().contains("duplicate key") => {
43 LedgerError::DuplicateKey(err)
44 }
45 e => LedgerError::Sqlx(e),
46 }
47 }
48}