schema_registry_lineage/
error.rs1use thiserror::Error;
4use uuid::Uuid;
5
6pub type Result<T> = std::result::Result<T, LineageError>;
8
9#[derive(Debug, Error)]
11pub enum LineageError {
12 #[error("Schema not found: {0}")]
14 SchemaNotFound(Uuid),
15
16 #[error("Dependency already exists: {from} -> {to}")]
18 DependencyExists { from: String, to: String },
19
20 #[error("Dependency not found: {from} -> {to}")]
22 DependencyNotFound { from: String, to: String },
23
24 #[error("Circular dependency detected: {0}")]
26 CircularDependency(String),
27
28 #[error("Invalid relationship type: {0}")]
30 InvalidRelationType(String),
31
32 #[error("Graph operation failed: {0}")]
34 GraphOperationFailed(String),
35
36 #[error("Export failed: {0}")]
38 ExportFailed(String),
39
40 #[error("Import failed: {0}")]
42 ImportFailed(String),
43
44 #[error("Invalid query filter: {0}")]
46 InvalidFilter(String),
47
48 #[error("Maximum traversal depth exceeded: {0}")]
50 MaxDepthExceeded(usize),
51
52 #[error("Entity not found: {0}")]
54 EntityNotFound(String),
55
56 #[error("Invalid entity type: {0}")]
58 InvalidEntityType(String),
59
60 #[error("Serialization error: {0}")]
62 SerializationError(String),
63
64 #[error("Deserialization error: {0}")]
66 DeserializationError(String),
67
68 #[error("Internal error: {0}")]
70 Internal(String),
71
72 #[error("Lock poisoned: {0}")]
74 LockPoisoned(String),
75
76 #[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}