Skip to main content

graphlite_sdk/
error.rs

1//! Error types for the GraphLite SDK
2
3use thiserror::Error;
4
5/// Result type alias for SDK operations
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Main error type for GraphLite SDK operations
9#[derive(Error, Debug)]
10pub enum Error {
11    /// Error from the core GraphLite library
12    #[error("GraphLite error: {0}")]
13    GraphLite(String),
14
15    /// Session-related errors
16    #[error("Session error: {0}")]
17    Session(String),
18
19    /// Query execution errors
20    #[error("Query error: {0}")]
21    Query(String),
22
23    /// Transaction errors
24    #[error("Transaction error: {0}")]
25    Transaction(String),
26
27    /// Serialization/deserialization errors
28    #[error("Serialization error: {0}")]
29    Serialization(#[from] serde_json::Error),
30
31    /// Type conversion errors
32    #[error("Type conversion error: {0}")]
33    TypeConversion(String),
34
35    /// Invalid operation errors
36    #[error("Invalid operation: {0}")]
37    InvalidOperation(String),
38
39    /// Resource not found errors
40    #[error("Not found: {0}")]
41    NotFound(String),
42
43    /// Connection errors
44    #[error("Connection error: {0}")]
45    Connection(String),
46
47    /// I/O errors
48    #[error("I/O error: {0}")]
49    Io(#[from] std::io::Error),
50}
51
52impl From<String> for Error {
53    fn from(s: String) -> Self {
54        Error::GraphLite(s)
55    }
56}
57
58impl From<&str> for Error {
59    fn from(s: &str) -> Self {
60        Error::GraphLite(s.to_string())
61    }
62}