odem_rs_core/
error.rs

1//! A module for core-specific error types.
2
3pub use crate::continuation::error::*;
4
5/* ************************************************************** Error Types */
6
7/// Enumeration of errors for the functions and structures contained in this
8/// module of the simulation library.
9#[derive(Copy, Clone, Debug, thiserror::Error)]
10pub enum Error {
11	/// The simulation stopped when the simulator detected a deadlock.
12	#[error("deadlock detected")]
13	Deadlock,
14	/// Continuation is already bound.
15	#[error(transparent)]
16	NotBorn(#[from] NotBorn),
17	/// Continuation is not idle.
18	#[error(transparent)]
19	NotIdle(#[from] NotIdle),
20	/// Continuation is not active.
21	#[error(transparent)]
22	NotBusy(#[from] NotBusy),
23	/// Continuation is not scheduled.
24	#[error(transparent)]
25	NotNext(#[from] NotNext),
26	/// Continuation hasn't completed yet.
27	#[error(transparent)]
28	NotDone(#[from] NotDone),
29	/// Continuation hasn't been released yet.
30	#[error(transparent)]
31	NotGone(#[from] NotGone),
32	/// Continuation hasn't been bound yet.
33	#[error(transparent)]
34	NotInit(#[from] NotInit),
35	/// Continuation hasn't terminated.
36	#[error(transparent)]
37	NotTerm(#[from] NotTerm),
38	/// Signals an attempt to schedule a continuation at an earlier model-time.
39	#[error("causality error")]
40	Causality,
41}
42
43/* ******************************************************** Minor Error Types */
44
45/// Signals the detection of a deadlock during a simulation run.
46#[derive(Copy, Clone, Debug, thiserror::Error)]
47pub struct Deadlock<T>(pub T);
48
49impl<T> From<Deadlock<T>> for Error {
50	fn from(_: Deadlock<T>) -> Self {
51		Error::Deadlock
52	}
53}
54
55impl<T: crate::config::Time> core::fmt::Display for Deadlock<T> {
56	fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
57		write!(f, "deadlock detected at {}", self.0.display())
58	}
59}
60
61/// Signals that an event at the current model time caused a change in that
62/// event's past, violating causality.
63#[derive(Copy, Clone, Debug, thiserror::Error)]
64#[error(
65	"continuation was scheduled at model-time {cause:?} (cause) for model-time \
66         {effect:?} (effect), violating causality"
67)]
68pub struct CausalityError<T> {
69	/// Source time of the caller.
70	pub cause: T,
71	/// Target model-time of the caller.
72	pub effect: T,
73}
74
75impl<T> From<CausalityError<T>> for Error {
76	fn from(_: CausalityError<T>) -> Self {
77		Error::Causality
78	}
79}