Skip to main content

schema_registry_lineage/
error.rs

1//! Error types for schema lineage tracking
2
3use thiserror::Error;
4use uuid::Uuid;
5
6/// Result type for lineage operations
7pub type Result<T> = std::result::Result<T, LineageError>;
8
9/// Errors that can occur during lineage tracking operations
10#[derive(Debug, Error)]
11pub enum LineageError {
12    /// Schema not found in the lineage graph
13    #[error("Schema not found: {0}")]
14    SchemaNotFound(Uuid),
15
16    /// Dependency already exists
17    #[error("Dependency already exists: {from} -> {to}")]
18    DependencyExists { from: String, to: String },
19
20    /// Dependency not found
21    #[error("Dependency not found: {from} -> {to}")]
22    DependencyNotFound { from: String, to: String },
23
24    /// Circular dependency detected
25    #[error("Circular dependency detected: {0}")]
26    CircularDependency(String),
27
28    /// Invalid relationship type
29    #[error("Invalid relationship type: {0}")]
30    InvalidRelationType(String),
31
32    /// Graph operation failed
33    #[error("Graph operation failed: {0}")]
34    GraphOperationFailed(String),
35
36    /// Export operation failed
37    #[error("Export failed: {0}")]
38    ExportFailed(String),
39
40    /// Import operation failed
41    #[error("Import failed: {0}")]
42    ImportFailed(String),
43
44    /// Invalid query filter
45    #[error("Invalid query filter: {0}")]
46    InvalidFilter(String),
47
48    /// Maximum depth exceeded
49    #[error("Maximum traversal depth exceeded: {0}")]
50    MaxDepthExceeded(usize),
51
52    /// Entity not found
53    #[error("Entity not found: {0}")]
54    EntityNotFound(String),
55
56    /// Invalid entity type
57    #[error("Invalid entity type: {0}")]
58    InvalidEntityType(String),
59
60    /// Serialization error
61    #[error("Serialization error: {0}")]
62    SerializationError(String),
63
64    /// Deserialization error
65    #[error("Deserialization error: {0}")]
66    DeserializationError(String),
67
68    /// Internal error
69    #[error("Internal error: {0}")]
70    Internal(String),
71
72    /// Lock poisoned
73    #[error("Lock poisoned: {0}")]
74    LockPoisoned(String),
75
76    /// I/O error
77    #[error("I/O error: {0}")]
78    IoError(#[from] std::io::Error),
79}
80
81impl From<serde_json::Error> for LineageError {
82    fn from(err: serde_json::Error) -> Self {
83        LineageError::SerializationError(err.to_string())
84    }
85}
86
87impl<T> From<std::sync::PoisonError<T>> for LineageError {
88    fn from(err: std::sync::PoisonError<T>) -> Self {
89        LineageError::LockPoisoned(err.to_string())
90    }
91}
92
93#[cfg(test)]
94mod tests {
95    use super::*;
96
97    #[test]
98    fn test_error_display() {
99        let id = Uuid::new_v4();
100        let err = LineageError::SchemaNotFound(id);
101        assert!(err.to_string().contains(&id.to_string()));
102
103        let err = LineageError::DependencyExists {
104            from: "A".to_string(),
105            to: "B".to_string(),
106        };
107        assert!(err.to_string().contains("A"));
108        assert!(err.to_string().contains("B"));
109    }
110
111    #[test]
112    fn test_result_type() {
113        let success: Result<i32> = Ok(42);
114        assert!(success.is_ok());
115
116        let failure: Result<i32> = Err(LineageError::Internal("test".to_string()));
117        assert!(failure.is_err());
118    }
119}