Skip to main content

mdbx_derive_traits/
error.rs

1use thiserror::Error;
2
3#[cfg(all(feature = "serde_json", not(feature = "simd-json")))]
4type JSONError = serde_json::Error;
5#[cfg(feature = "simd-json")]
6type JSONError = simd_json::Error;
7
8#[derive(Error, Debug)]
9pub enum MDBXDeriveError {
10    #[error("corrputed")]
11    Corrupted,
12    #[error("incorrect schema")]
13    IncorrectSchema(Vec<u8>),
14    #[cfg(any(feature = "serde_json", feature = "simd-json"))]
15    #[error("JSON: {0}")]
16    JSON(#[from] JSONError),
17    #[error("zstd: {0}")]
18    Zstd(#[from] std::io::Error),
19    #[error("postcard: {0}")]
20    Postcard(#[from] postcard::Error),
21    #[cfg(feature = "mdbx")]
22    #[error("mdbx: {0}")]
23    MDBX(#[from] libmdbx_remote::Error),
24    #[cfg(feature = "mdbx")]
25    #[error("mdbx-remote: {0}")]
26    Client(libmdbx_remote::ClientError),
27    #[error("bcs: {0}")]
28    BCS(#[from] bcs::Error),
29}
30
31#[cfg(feature = "mdbx")]
32impl From<libmdbx_remote::ClientError> for MDBXDeriveError {
33    fn from(value: libmdbx_remote::ClientError) -> Self {
34        match value {
35            libmdbx_remote::ClientError::MDBX(e) => Self::MDBX(e),
36            _ => Self::Client(value),
37        }
38    }
39}