Skip to main content

nanobook_risk/
error.rs

1//! Errors returned by the risk engine.
2
3use std::fmt;
4
5/// Errors returned by the risk engine.
6///
7/// Currently a single variant for configuration-validation failures;
8/// extending this enum is non-breaking provided it stays
9/// `#[non_exhaustive]`-friendly in spirit (match arms on library
10/// callers should include a catch-all).
11#[derive(Clone, Debug, PartialEq, Eq)]
12pub enum RiskError {
13    /// A `RiskConfig` failed [`RiskConfig::validate`] — malformed
14    /// numeric bounds (NaN, out-of-range, negative where non-negative
15    /// required) or a config produced by deserializing untrusted
16    /// input. The wrapped string is the failing-field message from
17    /// `validate`, suitable for direct display or log output.
18    ///
19    /// [`RiskConfig::validate`]: crate::config::RiskConfig::validate
20    InvalidConfig(String),
21}
22
23impl fmt::Display for RiskError {
24    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25        match self {
26            RiskError::InvalidConfig(msg) => write!(f, "invalid RiskConfig: {msg}"),
27        }
28    }
29}
30
31impl std::error::Error for RiskError {}