rstm_programs/
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    #[error("The actor has halted.")]
16    Halted,
17    #[error(
18        "The actor attempted to access an index ({index}) outside the bounds of the tape (size: {len})."
19    )]
20    IndexOutOfBounds { index: usize, len: usize },
21    #[error(transparent)]
22    CoreError(#[from] rstm_core::Error),
23    #[error(transparent)]
24    StateError(#[from] rstm_state::StateError),
25    #[error("An unknown error was thrown by an actor: {0}")]
26    UnknwonError(String),
27}
28
29#[cfg(feature = "alloc")]
30impl From<Error> for rstm_core::Error {
31    fn from(err: Error) -> Self {
32        match err {
33            Error::CoreError(e) => e,
34            e => rstm_core::Error::BoxError(Box::new(e)),
35        }
36    }
37}