wasccgraph_common/
errors.rs

1#[doc(hidden)]
2#[macro_export]
3macro_rules! client_type_error {
4    ($($arg:tt)*) => {
5        Err($crate::GraphError::ClientTypeError(format!($($arg)*)))
6    };
7}
8
9/// Common result type for this crate.
10pub type GraphResult<T> = Result<T, GraphError>;
11
12/// Common error type for this crate.
13#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14pub enum GraphError {
15    /// Returned if the data you requested is of a different type
16    /// than the data returned by the database.
17    ClientTypeError(String),
18
19    /// Returned if a label name was not found in the graph's internal registry.
20    ///
21    /// This error is taken care of by the implementation and should never reach your code.
22    LabelNotFound,
23    /// Returned if a relationship type name was not found in the graph's internal registry.
24    ///
25    /// This error is taken care of by the implementation and should never reach your code.
26    RelationshipTypeNotFound,
27    /// Returned if a property key name was not found in the graph's internal registry.
28    ///
29    /// This error is taken care of by the implementation and should never reach your code.
30    PropertyKeyNotFound,
31
32    /// Returned if you requested a [`String`](https://doc.rust-lang.org/std/string/struct.String.html) and the database responded with bytes that are invalid UTF-8.
33    ///
34    /// If you don't care about whether the data is valid UTF-8, consider requesting a [`RedisString`](../result_set/struct.RedisString.html) instead.
35    InvalidUtf8,
36}
37
38impl std::fmt::Display for GraphError {
39    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40        match self {
41            GraphError::ClientTypeError(e) => write!(f, "Graph client error: {}", e),
42            _ => write!(f, "Graph error"),
43        }
44    }
45}