eryon_rt/
error.rs

1/*
2    Appellation: error <module>
3    Contrib: @FL03
4*/
5/// a type alias for the [`Result`] type using the [`RuntimeError`] as the error type.
6pub(crate) type Result<T = ()> = core::result::Result<T, RuntimeError>;
7/// The [`RuntimeError`] enum defines the various errors that can occur in the runtime.
8#[derive(Debug, thiserror::Error)]
9pub enum RuntimeError {
10    #[error("Node not found")]
11    NodeNotFound,
12    #[error("Task not found")]
13    TaskNotFound(usize),
14    #[error("Failed to lock mutex")]
15    LockError,
16    #[error("Poisoned lock: {0}")]
17    PoisonError(String),
18    #[error(transparent)]
19    ActorError(#[from] eryon_actors::ActorError),
20    #[error(transparent)]
21    CoreError(#[from] eryon::Error),
22    #[error(transparent)]
23    MemError(#[from] eryon_mem::MemoryError),
24}
25
26impl From<RuntimeError> for eryon::Error {
27    fn from(err: RuntimeError) -> Self {
28        match err {
29            RuntimeError::CoreError(e) => e,
30            _ => eryon::Error::BoxError(Box::new(err)),
31        }
32    }
33}
34
35impl From<&str> for RuntimeError {
36    fn from(s: &str) -> Self {
37        eryon::Error::from(s).into()
38    }
39}
40
41impl From<String> for RuntimeError {
42    fn from(s: String) -> Self {
43        eryon::Error::from(s).into()
44    }
45}
46
47impl<E: 'static + Send + Sync> From<std::sync::PoisonError<E>> for RuntimeError {
48    fn from(err: std::sync::PoisonError<E>) -> Self {
49        RuntimeError::PoisonError(format!("{err}"))
50    }
51}
52
53impl<E> From<std::sync::TryLockError<E>> for RuntimeError {
54    fn from(_: std::sync::TryLockError<E>) -> Self {
55        RuntimeError::LockError
56    }
57}