Skip to main content

grid_billing/
error.rs

1//! Error types for `grid-billing`.
2
3/// Errors returned by the billing calculation functions.
4#[derive(Debug, Clone, thiserror::Error)]
5pub enum BillingError {
6    /// The billing input contains an invalid or inconsistent value.
7    #[error("invalid billing input: {reason}")]
8    InvalidInput {
9        /// Human-readable explanation. Dynamic `String` so callers can include runtime context.
10        reason: String,
11    },
12
13    /// Monetary precision overflow — the calculated amount exceeds `i64` range.
14    ///
15    /// This can only happen for unrealistically large billing amounts (> ~92 million EUR).
16    /// `input_value` carries the `Decimal` that caused the overflow so callers can log it.
17    #[error("monetary overflow: amount {input_value:?} too large for EuroAmount representation")]
18    MonetaryOverflow {
19        /// The value that caused the overflow, if available.
20        input_value: Option<rust_decimal::Decimal>,
21    },
22
23    /// The delivery period is governed by an Entgelt regime whose methodology
24    /// cannot be computed yet.
25    ///
26    /// StromNEV/GasNEV and the ARegV lapse with the end of 2028; the successor
27    /// system AgNeS (GBK-25-01) is draft only — the Rahmenfestlegung is
28    /// expected end-2026, and its parameter tables follow as configuration
29    /// once they become binding. Refusing is deliberate: computing under the
30    /// lapsed Verordnung math and merely tagging the result AgNeS would be
31    /// wrong under both regimes. See
32    /// [`crate::regulatory::RegulatoryRegime::ensure_berechenbar`].
33    #[error(
34        "cannot price Netzentgelte for Tarifjahr {tarifjahr}: the period is governed by the \
35         AgNeS Entgelt regime (GBK-25-01), whose parameter tables are not yet festgelegt — \
36         the Rahmenfestlegung is expected end-2026, and the methodology follows as \
37         configuration once binding"
38    )]
39    UnsupportedEntgeltRegime {
40        /// The calendar year whose rates the settlement would have priced.
41        tarifjahr: i32,
42    },
43}