Skip to main content

rosace_core/
error.rs

1/// Errors that can arise within the ROSACE framework.
2#[derive(Debug)]
3pub enum RosaceError {
4    /// A required resource could not be located.
5    NotFound { resource: &'static str },
6    /// The system is in an unexpected or inconsistent state.
7    InvalidState(String),
8    /// A layout computation failed or produced an invalid result.
9    LayoutError(String),
10    /// An unexpected internal error occurred.
11    Internal(String),
12}
13
14impl RosaceError {
15    /// Creates a `NotFound` error for the given resource name.
16    pub fn not_found(resource: &'static str) -> Self {
17        RosaceError::NotFound { resource }
18    }
19
20    /// Creates an `Internal` error with an arbitrary message.
21    pub fn internal(msg: impl Into<String>) -> Self {
22        RosaceError::Internal(msg.into())
23    }
24}
25
26impl std::fmt::Display for RosaceError {
27    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28        match self {
29            RosaceError::NotFound { resource } => write!(f, "resource not found: {resource}"),
30            RosaceError::InvalidState(msg) => write!(f, "invalid state: {msg}"),
31            RosaceError::LayoutError(msg) => write!(f, "layout error: {msg}"),
32            RosaceError::Internal(msg) => write!(f, "internal error: {msg}"),
33        }
34    }
35}
36
37impl std::error::Error for RosaceError {}
38
39/// Convenience alias for `Result<T, RosaceError>`.
40pub type RosaceResult<T> = Result<T, RosaceError>;