orbit/component/
error.rs

1//! Error types for component operations
2
3use std::any::TypeId;
4use std::error::Error;
5use std::fmt;
6
7use crate::component::LifecyclePhase;
8
9/// Errors that can occur during component operations
10#[derive(Debug)]
11pub enum ComponentError {
12    /// Component type not found in registry
13    TypeNotFound(TypeId),
14
15    /// Props type mismatch
16    PropsMismatch { expected: TypeId, got: TypeId },
17
18    /// Invalid props type for the component
19    InvalidPropsType,
20
21    /// Invalid props content or validation failed
22    InvalidProps(String),
23
24    /// Error downcasting props or component
25    DowncastError,
26
27    /// Error acquiring lock
28    LockError(String),
29
30    /// Invalid lifecycle transition
31    InvalidLifecycleTransition(LifecyclePhase, String),
32
33    /// Error rendering component
34    RenderError(String),
35
36    /// Error updating component
37    UpdateError(String),
38
39    /// Error mounting component
40    MountError(String),
41
42    /// Error unmounting component
43    UnmountError(String),
44
45    /// Error from reactive system
46    ReactiveSystemError(String),
47}
48
49impl fmt::Display for ComponentError {
50    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51        match self {
52            Self::TypeNotFound(type_id) => write!(f, "Component type {type_id:?} not found"),
53            Self::PropsMismatch { expected, got } => write!(
54                f,
55                "Props type mismatch - expected {expected:?}, got {got:?}"
56            ),
57            Self::InvalidPropsType => write!(f, "Invalid props type for the component"),
58            Self::DowncastError => write!(f, "Failed to downcast props or component"),
59            Self::LockError(msg) => write!(f, "Lock error: {msg}"),
60            Self::InvalidLifecycleTransition(phase, operation) => write!(
61                f,
62                "Invalid lifecycle transition: cannot {operation} while in {phase:?} phase"
63            ),
64            Self::RenderError(msg) => write!(f, "Error rendering component: {msg}"),
65            Self::UpdateError(msg) => write!(f, "Error updating component: {msg}"),
66            Self::MountError(msg) => write!(f, "Error mounting component: {msg}"),
67            Self::UnmountError(msg) => write!(f, "Error unmounting component: {msg}"),
68            Self::ReactiveSystemError(msg) => write!(f, "Reactive system error: {msg}"),
69            Self::InvalidProps(msg) => write!(f, "Invalid props: {msg}"),
70        }
71    }
72}
73
74impl Error for ComponentError {}
75
76// Conversion from SignalError to ComponentError
77impl From<crate::state::SignalError> for ComponentError {
78    fn from(error: crate::state::SignalError) -> Self {
79        ComponentError::ReactiveSystemError(error.to_string())
80    }
81}