Skip to main content

optionstratlib_visualization/error/
graph.rs

1//! Target crate (ADR-0001 D6, roadmap M1-14): **visualization**. Owns `GraphError`.
2
3use optionstratlib_backtest::error::BacktestError;
4use optionstratlib_core::error::DecimalError;
5use optionstratlib_math::error::{CurveError, SurfaceError};
6use thiserror::Error;
7
8/// Represents errors that can occur during graph generation and rendering operations.
9///
10/// This error type encapsulates failures that may happen when creating, rendering,
11/// or saving graphical representations of financial data such as option chains,
12/// volatility surfaces, or strategy payoffs.
13#[derive(Error, Debug)]
14pub enum GraphError {
15    /// Represents errors that occur during the rendering process.
16    /// Contains a descriptive message about what went wrong.
17    #[error("Render error: {0}")]
18    Render(String),
19
20    /// Represents I/O errors that occur when reading from or writing to files
21    /// (e.g., when saving graphs to disk).
22    #[error("IO error: {0}")]
23    Io(#[from] std::io::Error),
24
25    /// Error from curve operations.
26    #[error(transparent)]
27    Curve(CurveError),
28
29    /// Error from surface operations.
30    #[error(transparent)]
31    Surface(SurfaceError),
32
33    /// A figure a report derives for display (a total, an average) left the
34    /// representable `Decimal` range.
35    #[error(transparent)]
36    Decimal(Box<DecimalError>),
37
38    /// The backtest figures a report shows could not be computed, for
39    /// example when the statistics of a `SimulationStats` accumulator
40    /// overflow `Decimal`.
41    #[error(transparent)]
42    Backtest(Box<BacktestError>),
43}
44
45impl From<BacktestError> for GraphError {
46    #[cold]
47    #[inline(never)]
48    fn from(err: BacktestError) -> Self {
49        GraphError::Backtest(Box::new(err))
50    }
51}
52
53impl From<DecimalError> for GraphError {
54    #[cold]
55    #[inline(never)]
56    fn from(err: DecimalError) -> Self {
57        GraphError::Decimal(Box::new(err))
58    }
59}
60
61impl From<CurveError> for GraphError {
62    #[cold]
63    #[inline(never)]
64    fn from(err: CurveError) -> Self {
65        GraphError::Curve(err)
66    }
67}
68
69impl From<SurfaceError> for GraphError {
70    #[cold]
71    #[inline(never)]
72    fn from(err: SurfaceError) -> Self {
73        GraphError::Surface(err)
74    }
75}