#[non_exhaustive]pub enum BillingError {
MonetaryOverflow {
precision: u8,
input_value: Option<Decimal>,
},
PrecisionLoss {
precision: u8,
input_value: Decimal,
},
InvalidSchedule {
reason: String,
},
InvalidInput {
reason: String,
},
ValidationFailed {
check: String,
actual: String,
expected: String,
},
InvalidAllocationShares {
sum: String,
},
ZeroPeriod,
LayerError {
reason: String,
},
CurrencyMismatch {
left: Currency,
right: Currency,
},
Parse(ParseAmountError),
}Expand description
All errors produced by the billing engine.
This enum is #[non_exhaustive]: new variants may be added in minor releases
without a semver-major bump. Always include a _ => arm when matching.
§Error context
BillingError::MonetaryOverflow carries input_value: Option<Decimal> —
the input that caused the overflow when known. This lets callers log the
offending value:
use billing::{Amount, BillingError};
use rust_decimal::Decimal;
let huge = Decimal::from(i64::MAX / 100_000 + 1);
match Amount::<5>::checked_from_decimal(huge) {
Ok(a) => println!("ok: {a}"),
Err(BillingError::MonetaryOverflow { input_value: Some(v), precision }) => {
eprintln!("overflow: {v} does not fit in Amount<{precision}>");
}
Err(e) => eprintln!("other error: {e}"),
}BillingError::InvalidInput and BillingError::InvalidSchedule carry a
reason: String which accepts both &'static str literals (via .into()) and
dynamic messages (format!("{}", value)).
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
MonetaryOverflow
An arithmetic operation on an crate::Amount exceeded the i64 range.
input_value carries the original Decimal that caused the overflow
when known (e.g. from crate::Amount::checked_from_decimal). It is
None for internal arithmetic operations (add / sub / mul) where no
single input value is solely responsible.
Fields
PrecisionLoss
A Decimal carried more non-zero fractional digits than the target
crate::Amount<P> can represent.
This is not overflow: the magnitude fits, the precision does not.
Amount::<5>::checked_from_decimal(dec!(0.123456)) reports it, exactly as
Amount::<5>::parse("0.123456") is rejected — the two conversion paths
agree by construction.
To round instead of refusing, name the rounding you want with
crate::Amount::from_decimal_rounded.
Fields
InvalidSchedule
A crate::RateSchedule was built or used incorrectly.
Fields
InvalidInput
A function argument was invalid.
Fields
ValidationFailed
crate::BillingDocument::assert_valid detected an arithmetic inconsistency.
The check field identifies which invariant failed. The set is stable
enough to match on, and every value it can take is listed here:
| Emitted by | check |
|---|---|
crate::BillingDocument::validate totals | "net_total", "tax_total", "gross_total", "discount_total" |
| …VAT breakdown | "tax_breakdown", "tax_breakdown_total", "vat_breakdown_presence" |
| …settlement | "prepaid", "prepaid_vs_prepayment", "rounding" |
| …positions | "net_positions", "discount_positions", "tax_positions" |
crate::BillingDocument::verify_vat_attribution | "vat_attribution", "vat_total" |
Fields
crate::ProportionalAllocation shares do not sum to 1.0 ± 1e-9.
ZeroPeriod
crate::prorate was called with total_days = 0.
LayerError
A crate::TaxLayer or crate::DiscountLayer compute call failed.
CurrencyMismatch
Two amounts or documents in different currencies were combined.
Produced by crate::merge_period_documents. Adding amounts across
currencies is never meaningful, so the engine refuses rather than silently
producing a nonsense total.
Fields
Parse(ParseAmountError)
An crate::Amount could not be parsed from its textual form.
Wraps ParseAmountError so that parsing composes with ? inside
functions returning BillingError.
Trait Implementations§
Source§impl Clone for BillingError
impl Clone for BillingError
Source§fn clone(&self) -> BillingError
fn clone(&self) -> BillingError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BillingError
impl Debug for BillingError
Source§impl Display for BillingError
impl Display for BillingError
Source§impl Error for BillingError
impl Error for BillingError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<!> for BillingError
Infallible → BillingError conversion needed when PricingModel::Error = Infallible.
impl From<!> for BillingError
Infallible → BillingError conversion needed when PricingModel::Error = Infallible.
Source§fn from(x: !) -> BillingError
fn from(x: !) -> BillingError
Source§impl From<BillingError> for EngineError
impl From<BillingError> for EngineError
Source§fn from(source: BillingError) -> Self
fn from(source: BillingError) -> Self
Source§impl From<ParseAmountError> for BillingError
Lets Amount::parse(..)? compose inside functions returning BillingError.
impl From<ParseAmountError> for BillingError
Lets Amount::parse(..)? compose inside functions returning BillingError.