1use std::fmt;
4
5#[derive(Debug)]
7pub enum Error {
8 LockPoisoned,
10
11 Io(std::io::Error),
13
14 Serialization(String),
16
17 Storage(String),
19
20 Transaction(String),
22
23 InvalidOperation(String),
25
26 InvalidInput(String),
28
29 NotFound,
31
32 Corruption(String),
34}
35
36impl fmt::Display for Error {
37 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 match self {
39 Error::LockPoisoned => write!(f, "Lock poisoned"),
40 Error::Io(e) => write!(f, "I/O error: {}", e),
41 Error::Serialization(msg) => write!(f, "Serialization error: {}", msg),
42 Error::Storage(msg) => write!(f, "Storage error: {}", msg),
43 Error::Transaction(msg) => write!(f, "Transaction error: {}", msg),
44 Error::InvalidOperation(msg) => write!(f, "Invalid operation: {}", msg),
45 Error::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
46 Error::NotFound => write!(f, "Not found"),
47 Error::Corruption(msg) => write!(f, "Data corruption: {}", msg),
48 }
49 }
50}
51
52impl std::error::Error for Error {
53 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
54 match self {
55 Error::Io(e) => Some(e),
56 _ => None,
57 }
58 }
59}
60
61impl From<std::io::Error> for Error {
62 fn from(err: std::io::Error) -> Self {
63 Error::Io(err)
64 }
65}
66
67pub type Result<T> = std::result::Result<T, Error>;