Skip to main content

dpp_calc/kernel/
error.rs

1//! Error type for all calculator operations in `dpp-calc`.
2
3#[derive(Debug, thiserror::Error)]
4pub enum CalcError {
5    #[error("invalid input: {0}")]
6    InvalidInput(String),
7
8    /// The ruleset's effective period has ended; a newer version is required.
9    #[error("ruleset '{id}' expired on {until}")]
10    RulesetExpired { id: String, until: String },
11
12    /// The ruleset's effective period has a known start date that has not
13    /// arrived yet.
14    #[error("ruleset '{id}' is not yet effective (in force from {from})")]
15    RulesetNotYetEffective { id: String, from: String },
16
17    /// The ruleset has no application date at all, because the instrument that
18    /// would date it has not entered into force. Distinct from
19    /// [`RulesetNotYetEffective`](Self::RulesetNotYetEffective): that one knows
20    /// the date and is waiting for it, this one cannot know it yet.
21    #[error("ruleset '{id}' has no application date yet — awaiting {empowerment}")]
22    RulesetUndetermined { id: String, empowerment: String },
23
24    /// A computation overflowed to a non-finite value despite finite, in-range
25    /// inputs — a legally cited figure must never silently become Infinity.
26    #[error("calculation overflow: {0}")]
27    Overflow(String),
28
29    /// The requested activity UUID is not present in the injected factor dataset.
30    #[error("emission factor not found for activity '{0}'")]
31    FactorNotFound(String),
32
33    /// The supplied data cannot be processed by this methodology.
34    #[error("methodology mismatch: {0}")]
35    MethodologyMismatch(String),
36
37    /// The methodology is defined but not yet implemented (gate: data license / delegated act).
38    #[error("not implemented: {methodology} — {reason}")]
39    NotImplemented { methodology: String, reason: String },
40
41    /// A parameter combination that is internally incoherent per the ruleset.
42    #[error("cross-field validation failed: {0}")]
43    CrossFieldViolation(String),
44
45    /// JSON canonicalization failed — inputs or outputs could not be serialized.
46    #[error("canonicalization error: {0}")]
47    CanonicalizeError(String),
48}