Skip to main content

rstm_actors/
error.rs

1/*
2    Appellation: error <module>
3    Contrib: FL03 <jo3mccain@icloud.com>
4*/
5//! This module defines the custom error type for handling various actor-related errors.
6#[cfg(feature = "alloc")]
7use alloc::{boxed::Box, string::String};
8
9/// A type alias for a [`Result`](core::result::Result) that uses the custom [`Error`] type
10pub type Result<T> = core::result::Result<T, Error>;
11
12/// the various errors that can occur in the state module
13#[derive(Debug, thiserror::Error)]
14pub enum Error {
15    #[cfg(feature = "alloc")]
16    #[error("[Execution Error] {0}")]
17    ExecutionError(String),
18    #[error("The actor is halted and should be terminated.")]
19    Halted,
20    #[error("The actor is not ready to process inputs.")]
21    NotReady,
22    #[error("The actor has no program loaded.")]
23    NoProgram,
24    #[error("The actor has no inputs to process.")]
25    NoInputs,
26    #[error("An infinite loop was detected during execution.")]
27    InfiniteLoop,
28    #[error("No rule found")]
29    NoRuleFound,
30    #[error("No symbol found at position {0}.")]
31    NoSymbolFound(usize),
32    #[error(transparent)]
33    CoreError(#[from] rstm_core::Error),
34    #[error(transparent)]
35    ProgramsError(#[from] rstm_programs::Error),
36    #[error(transparent)]
37    StateError(#[from] rstm_state::StateError),
38}
39
40#[cfg(feature = "alloc")]
41impl From<Error> for rstm_core::Error {
42    fn from(err: Error) -> Self {
43        match err {
44            Error::CoreError(e) => e,
45            e => rstm_core::Error::BoxError(Box::new(e)),
46        }
47    }
48}