Skip to main content

credit_facility_rs/
errors.rs

1use thiserror::Error;
2use uuid::Uuid;
3
4use crate::decimal::{Money, Rate};
5use crate::types::FacilityStatus;
6
7#[derive(Error, Debug)]
8pub enum FacilityError {
9    #[error("insufficient funds: available {available}, requested {requested}")]
10    InsufficientFunds {
11        available: Money,
12        requested: Money,
13    },
14    
15    #[error("ltv breach: {ltv} exceeds threshold {threshold}")]
16    LtvBreach {
17        ltv: Rate,
18        threshold: Rate,
19    },
20    
21    #[error("invalid payment amount: {amount}")]
22    InvalidPaymentAmount {
23        amount: Money,
24    },
25    
26    #[error("facility not active: current status is {status:?}")]
27    FacilityNotActive {
28        status: FacilityStatus,
29    },
30    
31    #[error("overdraft limit exceeded: limit {limit}, requested {requested}")]
32    OverdraftLimitExceeded {
33        limit: Money,
34        requested: Money,
35    },
36    
37    #[error("credit limit exceeded: limit {limit}, requested {requested}")]
38    CreditLimitExceeded {
39        limit: Money,
40        requested: Money,
41    },
42    
43    #[error("milestone not found: {id}")]
44    MilestoneNotFound {
45        id: Uuid,
46    },
47    
48    #[error("milestone not approved for disbursement: {name}")]
49    MilestoneNotApproved {
50        name: String,
51    },
52    
53    #[error("invalid configuration: {message}")]
54    InvalidConfiguration {
55        message: String,
56    },
57    
58    #[error("liquidation in progress")]
59    LiquidationInProgress,
60    
61    #[error("payment schedule not applicable for facility type")]
62    PaymentScheduleNotApplicable,
63    
64    #[error("collateral required for this operation")]
65    CollateralRequired,
66    
67    #[error("no collateral associated with facility")]
68    NoCollateral,
69    
70    #[error("invalid date: {message}")]
71    InvalidDate {
72        message: String,
73    },
74    
75    #[error("calculation error: {message}")]
76    CalculationError {
77        message: String,
78    },
79    
80    #[error("facility already settled")]
81    FacilityAlreadySettled,
82    
83    #[error("facility already charged off")]
84    FacilityChargedOff,
85    
86    #[error("invalid interest rate: {rate}")]
87    InvalidInterestRate {
88        rate: Rate,
89    },
90    
91    #[error("payment less than minimum: minimum {minimum}, provided {provided}")]
92    PaymentBelowMinimum {
93        minimum: Money,
94        provided: Money,
95    },
96    
97    #[error("operation not supported for facility type")]
98    OperationNotSupported,
99    
100    #[error("draw period has ended")]
101    DrawPeriodEnded,
102    
103    #[error("invalid draw amount: {amount}")]
104    InvalidDrawAmount {
105        amount: Money,
106    },
107    
108    #[error("below minimum drawdown: minimum {minimum}, requested {requested}")]
109    BelowMinimumDrawdown {
110        minimum: Money,
111        requested: Money,
112    },
113    
114    #[error("exceeds credit limit: available {available}, requested {requested}")]
115    ExceedsCreditLimit {
116        available: Money,
117        requested: Money,
118    },
119    
120    #[error("invalid collateral: {message}")]
121    InvalidCollateral {
122        message: String,
123    },
124    
125    #[error("insufficient collateral: available {available}, required {required}")]
126    InsufficientCollateral {
127        available: rust_decimal::Decimal,
128        required: rust_decimal::Decimal,
129    },
130    
131    #[error("margin call expired: deadline {deadline}, current time {current_time}")]
132    MarginCallExpired {
133        deadline: chrono::DateTime<chrono::Utc>,
134        current_time: chrono::DateTime<chrono::Utc>,
135    },
136    
137    #[error("invalid state: current {current}, expected {expected}")]
138    InvalidState {
139        current: String,
140        expected: String,
141    },
142}
143
144pub type Result<T> = std::result::Result<T, FacilityError>;