1use crate::{
6 coding::{DecodeError, EncodeError},
7 version::Version,
8 Checksum, CompressionType,
9};
10
11#[derive(Debug)]
13#[non_exhaustive]
14pub enum Error {
15 Io(std::io::Error),
17
18 Encode(EncodeError),
20
21 Decode(DecodeError),
23
24 Decompress(CompressionType),
26
27 InvalidVersion(Version),
29
30 Unrecoverable,
32
33 InvalidChecksum((Checksum, Checksum)),
35
36 ValueLog(value_log::Error),
38}
39
40impl std::fmt::Display for Error {
41 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42 write!(f, "LsmTreeError: {self:?}")
43 }
44}
45
46impl std::error::Error for Error {
47 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
48 match self {
49 Self::Io(e) => Some(e),
50 Self::Encode(e) => Some(e),
51 Self::Decode(e) => Some(e),
52 Self::ValueLog(e) => Some(e),
53 Self::Decompress(_)
54 | Self::InvalidVersion(_)
55 | Self::Unrecoverable
56 | Self::InvalidChecksum(_) => None,
57 }
58 }
59}
60
61impl From<std::io::Error> for Error {
62 fn from(value: std::io::Error) -> Self {
63 Self::Io(value)
64 }
65}
66
67impl From<EncodeError> for Error {
68 fn from(value: EncodeError) -> Self {
69 Self::Encode(value)
70 }
71}
72
73impl From<DecodeError> for Error {
74 fn from(value: DecodeError) -> Self {
75 Self::Decode(value)
76 }
77}
78
79impl From<value_log::Error> for Error {
80 fn from(value: value_log::Error) -> Self {
81 Self::ValueLog(value)
82 }
83}
84
85pub type Result<T> = std::result::Result<T, Error>;