Skip to main content

BillingError

Enum BillingError 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

§precision: u8

The precision P of the overflowing Amount<P>.

§input_value: Option<Decimal>

The input value that caused the overflow, when known. Callers can log this to identify which amount triggered the overflow.

§

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

§precision: u8

The precision P of the target Amount<P>.

§input_value: Decimal

The value that could not be represented exactly.

§

InvalidSchedule

A crate::RateSchedule was built or used incorrectly.

Fields

§reason: String

Human-readable explanation. Accepts static literals ("msg".into()) and dynamic messages (format!(...)).

§

InvalidInput

A function argument was invalid.

Fields

§reason: String

Human-readable explanation. Accepts static literals ("msg".into()) and dynamic messages (format!(...)).

§

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 bycheck
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

§check: String

Which consistency check failed.

§actual: String

The value computed from positions.

§expected: String

The value stored in the totals field.

§

InvalidAllocationShares

crate::ProportionalAllocation shares do not sum to 1.0 ± 1e-9.

Fields

§sum: String

The actual sum of the provided shares.

§

ZeroPeriod

crate::prorate was called with total_days = 0.

§

LayerError

A crate::TaxLayer or crate::DiscountLayer compute call failed.

Fields

§reason: String

Human-readable explanation from the layer implementation.

§

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

§left: Currency

The currency of the left-hand / first operand.

§right: Currency

The currency of the right-hand / second operand.

§

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

Source§

fn clone(&self) -> BillingError

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BillingError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for BillingError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Error for BillingError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<!> for BillingError

InfallibleBillingError conversion needed when PricingModel::Error = Infallible.

Source§

fn from(x: !) -> BillingError

Converts to this type from the input type.
Source§

impl From<BillingError> for EngineError

Source§

fn from(source: BillingError) -> Self

Converts to this type from the input type.
Source§

impl From<ParseAmountError> for BillingError

Lets Amount::parse(..)? compose inside functions returning BillingError.

Source§

fn from(e: ParseAmountError) -> BillingError

Converts to this type from the input type.
Source§

impl PartialEq for BillingError

Source§

fn eq(&self, other: &BillingError) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for BillingError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more