Implemented thiserror.
This commit is contained in:
@@ -146,37 +146,24 @@ impl TryFrom<String> for WeekendAdjustment {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum RecurringTransactionConversionError {
|
||||
#[error("invalid amount_cents value: {0}")]
|
||||
AmountCents(i64),
|
||||
Direction(DirectionConversionError),
|
||||
|
||||
#[error(transparent)]
|
||||
Direction(#[from] DirectionConversionError),
|
||||
|
||||
#[error("invalid recurrence_every value: {0}")]
|
||||
RecurrenceEvery(i32),
|
||||
|
||||
#[error("invalid recurrence_unit value: {0}")]
|
||||
RecurrenceUnit(String),
|
||||
|
||||
#[error("invalid weekend_adjustment value: {0}")]
|
||||
WeekendAdjustment(String),
|
||||
}
|
||||
|
||||
impl std::error::Error for RecurringTransactionConversionError {}
|
||||
|
||||
impl std::fmt::Display for RecurringTransactionConversionError {
|
||||
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::AmountCents(value) => {
|
||||
write!(formatter, "invalid amount_cents value: {value}")
|
||||
}
|
||||
Self::Direction(error) => error.fmt(formatter),
|
||||
Self::RecurrenceEvery(value) => {
|
||||
write!(formatter, "invalid recurrence_every value: {value}")
|
||||
}
|
||||
Self::RecurrenceUnit(value) => {
|
||||
write!(formatter, "invalid recurrence_unit value: {value}")
|
||||
}
|
||||
Self::WeekendAdjustment(value) => {
|
||||
write!(formatter, "invalid weekend_adjustment value: {value}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use chrono::{TimeZone, Utc};
|
||||
|
||||
Reference in New Issue
Block a user