Skip to main content

moonpool_core/
error.rs

1//! Error types for simulation operations.
2
3use thiserror::Error;
4
5/// Errors that can occur during simulation operations.
6#[derive(Debug, Clone, PartialEq, Eq, Error)]
7pub enum SimulationError {
8    /// The simulation has been shut down and is no longer accessible.
9    #[error("Simulation has been shut down")]
10    SimulationShutdown,
11    /// The simulation is in an invalid state.
12    #[error("Invalid simulation state: {0}")]
13    InvalidState(String),
14    /// An I/O error occurred during simulation.
15    #[error("I/O error: {0}")]
16    IoError(String),
17    /// The simulation did not settle within the timeout after shutdown.
18    #[error("Settle timeout: {pending_events} events still pending after {elapsed:?}")]
19    SettleTimeout {
20        /// Number of events still pending when timeout was reached.
21        pending_events: usize,
22        /// How long the settle phase ran before timing out.
23        elapsed: std::time::Duration,
24    },
25}
26
27/// A type alias for `Result<T, SimulationError>`.
28pub type SimulationResult<T> = Result<T, SimulationError>;
29
30impl From<std::io::Error> for SimulationError {
31    fn from(err: std::io::Error) -> Self {
32        SimulationError::IoError(err.to_string())
33    }
34}