Skip to main content

laminar_core/mv/
error.rs

1//! Error types for materialized view operations.
2
3use thiserror::Error;
4
5/// Errors that can occur during materialized view operations.
6#[derive(Debug, Error)]
7pub enum MvError {
8    /// Attempted to register a view with a name that already exists.
9    #[error("materialized view already exists: {0}")]
10    DuplicateName(String),
11
12    /// A source referenced by the view does not exist.
13    #[error("source not found: {0}")]
14    SourceNotFound(String),
15
16    /// Registration would create a dependency cycle.
17    #[error("dependency cycle detected involving: {0}")]
18    CycleDetected(String),
19
20    /// The materialized view was not found.
21    #[error("materialized view not found: {0}")]
22    ViewNotFound(String),
23
24    /// The operator for a view was not found.
25    #[error("operator not found for view: {0}")]
26    OperatorNotFound(String),
27
28    /// Cannot drop view because other views depend on it.
29    #[error("cannot drop view '{0}': dependent views exist: {1:?}")]
30    HasDependents(String, Vec<String>),
31
32    /// Operator error during processing.
33    #[error("operator error: {0}")]
34    OperatorError(#[from] crate::operator::OperatorError),
35
36    /// State serialization/deserialization error.
37    #[error("serialization error: {0}")]
38    SerializationError(String),
39
40    /// View is in an invalid state for the requested operation.
41    #[error("view '{0}' is in invalid state: {1:?}")]
42    InvalidState(String, MvState),
43
44    /// Watermark propagation error.
45    #[error("watermark propagation error: {0}")]
46    WatermarkError(String),
47}
48
49/// Materialized view execution state.
50#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
51pub enum MvState {
52    /// View is actively processing events.
53    #[default]
54    Running,
55    /// View is paused (e.g., waiting for dependency).
56    Paused,
57    /// View encountered an error.
58    Error,
59    /// View is being dropped.
60    Dropping,
61}
62
63impl MvState {
64    /// Returns true if the view is in a state that can process events.
65    #[must_use]
66    pub fn can_process(&self) -> bool {
67        matches!(self, Self::Running)
68    }
69
70    /// Returns true if the view is in an error state.
71    #[must_use]
72    pub fn is_error(&self) -> bool {
73        matches!(self, Self::Error)
74    }
75}