1use std::fmt;
2
3#[derive(Debug)]
5pub enum Error {
6 Io(std::io::Error),
8 Storage(String),
10 Query(String),
12 Other(String),
14}
15
16impl fmt::Display for Error {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 match self {
19 Error::Io(e) => write!(f, "IO error: {}", e),
20 Error::Storage(e) => write!(f, "Storage error: {}", e),
21 Error::Query(e) => write!(f, "Query error: {}", e),
22 Error::Other(e) => write!(f, "Error: {}", e),
23 }
24 }
25}
26
27impl std::error::Error for Error {
28 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
29 match self {
30 Error::Io(e) => Some(e),
31 _ => None,
32 }
33 }
34}
35
36impl From<std::io::Error> for Error {
37 fn from(e: std::io::Error) -> Self {
38 Error::Io(e)
39 }
40}
41
42impl From<nervusdb_v2_storage::Error> for Error {
44 fn from(e: nervusdb_v2_storage::Error) -> Self {
45 match e {
46 nervusdb_v2_storage::Error::Io(e) => Error::Io(e),
47 _ => Error::Storage(e.to_string()),
48 }
49 }
50}
51
52impl From<nervusdb_v2_query::Error> for Error {
54 fn from(e: nervusdb_v2_query::Error) -> Self {
55 match e {
56 nervusdb_v2_query::Error::Io(e) => Error::Io(e),
57 _ => Error::Query(e.to_string()),
58 }
59 }
60}
61
62pub type Result<T> = std::result::Result<T, Error>;