eryon_core/
error.rs

1/*
2    Appellation: error <module>
3    Contrib: @FL03
4*/
5#[cfg(feature = "alloc")]
6use alloc::{boxed::Box, string::String};
7
8/// A type alias for a [`Result`](core::result::Result) with a custom error type ([Error])
9pub type Result<T = ()> = core::result::Result<T, Error>;
10
11/// The [`Error`] type enumerates the core errors that are handled by the framework
12#[derive(Debug, thiserror::Error)]
13pub enum Error {
14    #[error("Invalid Critical Point")]
15    InvalidCriticalPoint,
16    #[error("Invalid Operation")]
17    InvalidOperation,
18    #[error("Invalid Parameter")]
19    InvalidParameter,
20    #[error("Infinite loop detected")]
21    InfiniteLoop,
22    #[error("Lock Error")]
23    LockError,
24    #[error("Node not found")]
25    NodeNotFound,
26    #[error("Transformation Error")]
27    TransformationError,
28    #[cfg(feature = "alloc")]
29    #[error("Driver Error: {0}")]
30    DriverError(String),
31    #[cfg(feature = "alloc")]
32    #[error("Invalid State: {0}")]
33    InvalidState(String),
34    #[cfg(feature = "alloc")]
35    #[error("Invalid Symbol: {0}")]
36    InvalidSymbol(String),
37    #[cfg(feature = "alloc")]
38    #[error("Generative Error: {0}")]
39    GenerativeError(String),
40    #[cfg(feature = "alloc")]
41    #[error("Parse Error: {0}")]
42    ParseError(String),
43    #[error(transparent)]
44    MusicError(#[from] rstmt::Error),
45    #[error(transparent)]
46    TriadError(#[from] rstmt::nrt::TriadError),
47    #[cfg(feature = "anyhow")]
48    #[error(transparent)]
49    AnyError(#[from] anyhow::Error),
50    #[cfg(feature = "alloc")]
51    #[error(transparent)]
52    BoxError(#[from] Box<dyn core::error::Error + Send + Sync>),
53    #[cfg(feature = "serde")]
54    #[error(transparent)]
55    DeserializeError(#[from] serde::de::value::Error),
56    #[error(transparent)]
57    FmtError(#[from] core::fmt::Error),
58    #[error(transparent)]
59    GraphError(#[from] rshyper::Error),
60    #[cfg(feature = "std")]
61    #[error(transparent)]
62    IOError(#[from] std::io::Error),
63    #[cfg(feature = "json")]
64    #[error(transparent)]
65    JsonError(#[from] serde_json::Error),
66    #[error("Unknown Error: {0}")]
67    Unknown(String),
68}
69
70impl From<&str> for Error {
71    fn from(s: &str) -> Self {
72        Self::Unknown(String::from(s))
73    }
74}
75
76impl From<String> for Error {
77    fn from(s: String) -> Self {
78        Self::Unknown(s)
79    }
80}
81
82#[cfg(feature = "std")]
83impl<E> From<std::sync::PoisonError<E>> for Error {
84    fn from(_: std::sync::PoisonError<E>) -> Self {
85        Error::LockError
86    }
87}
88
89#[cfg(feature = "std")]
90impl<E> From<std::sync::TryLockError<E>> for Error {
91    fn from(_: std::sync::TryLockError<E>) -> Self {
92        Error::LockError
93    }
94}