Skip to main content

type_bridge_server/
error.rs

1#[derive(Debug, thiserror::Error)]
2/// Errors surfaced by configuration, validation, execution, and interception.
3pub enum PipelineError {
4    /// Server configuration could not be loaded or validated.
5    #[error("Configuration error: {0}")]
6    Config(String),
7    /// The configured TypeDB endpoint could not be reached.
8    #[error("TypeDB connection error: {0}")]
9    Connection(String),
10    /// The connected TypeDB server version is outside the supported matrix.
11    #[error("Unsupported version: {0}")]
12    UnsupportedVersion(#[from] type_bridge_core_lib::version::VersionError),
13    /// Provider execution rejected or failed the query.
14    #[error("Query execution error: {0}")]
15    QueryExecution(String),
16    /// Static query validation failed.
17    #[error("Validation error: {0}")]
18    Validation(String),
19    /// Query text or wire input could not be parsed.
20    #[error("Parse error: {0}")]
21    Parse(String),
22    /// The configured schema could not be loaded or decoded.
23    #[error("Schema error: {0}")]
24    Schema(String),
25    /// An interceptor rejected or failed the request.
26    #[error("Interceptor error: {0}")]
27    Interceptor(String),
28    /// An unexpected internal invariant failed.
29    #[error("Internal error: {0}")]
30    Internal(String),
31}
32
33#[cfg(test)]
34#[cfg_attr(coverage_nightly, coverage(off))]
35mod tests {
36    use super::*;
37
38    #[test]
39    fn display_config_error() {
40        let e = PipelineError::Config("bad config".into());
41        assert_eq!(e.to_string(), "Configuration error: bad config");
42    }
43
44    #[test]
45    fn display_connection_error() {
46        let e = PipelineError::Connection("refused".into());
47        assert_eq!(e.to_string(), "TypeDB connection error: refused");
48    }
49
50    #[test]
51    fn display_query_execution_error() {
52        let e = PipelineError::QueryExecution("syntax error".into());
53        assert_eq!(e.to_string(), "Query execution error: syntax error");
54    }
55
56    #[test]
57    fn display_validation_error() {
58        let e = PipelineError::Validation("invalid type".into());
59        assert_eq!(e.to_string(), "Validation error: invalid type");
60    }
61
62    #[test]
63    fn display_parse_error() {
64        let e = PipelineError::Parse("unexpected token".into());
65        assert_eq!(e.to_string(), "Parse error: unexpected token");
66    }
67
68    #[test]
69    fn display_schema_error() {
70        let e = PipelineError::Schema("file not found".into());
71        assert_eq!(e.to_string(), "Schema error: file not found");
72    }
73
74    #[test]
75    fn display_interceptor_error() {
76        let e = PipelineError::Interceptor("access denied".into());
77        assert_eq!(e.to_string(), "Interceptor error: access denied");
78    }
79
80    #[test]
81    fn display_internal_error() {
82        let e = PipelineError::Internal("unexpected".into());
83        assert_eq!(e.to_string(), "Internal error: unexpected");
84    }
85
86    #[test]
87    fn debug_format() {
88        let e = PipelineError::Config("test".into());
89        let debug = format!("{:?}", e);
90        assert!(debug.contains("Config"));
91    }
92
93    #[test]
94    fn display_unsupported_version_error() {
95        use type_bridge_core_lib::version::{Version, VersionError};
96        let inner = VersionError::Unsupported {
97            component: "server",
98            found: Version::new(2, 28, 0),
99        };
100        let e = PipelineError::UnsupportedVersion(inner);
101        let msg = e.to_string();
102        assert!(msg.contains("Unsupported version"), "missing prefix: {msg}");
103        assert!(msg.contains("2.28.0"), "missing detected version: {msg}");
104    }
105}