use thiserror::Error;
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum ParseAmountError {
#[error("amount must not be empty")]
Empty,
#[error("amount {input:?} is not a plain decimal number")]
Malformed {
input: String,
},
#[error("amount {input:?} has more than {max} decimals (EN 16931-1 §6.5.2)")]
TooManyDecimals {
input: String,
max: u8,
},
#[error("amount {input:?} is outside the representable range")]
OutOfRange {
input: String,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum AmountError {
#[error("monetary overflow")]
Overflow,
#[error("value {value} needs more than {max} decimals; reduce precision at the source")]
PrecisionLoss {
value: String,
max: u8,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum ParseDateError {
#[error("date {input:?} is not an ISO 8601 calendar date (YYYY-MM-DD)")]
Malformed {
input: String,
},
#[error("date {year:04}-{month:02}-{day:02} does not exist")]
NotACalendarDay {
year: i32,
month: u8,
day: u8,
},
}