diff --git a/crates/storage/libmdbx-rs/src/error.rs b/crates/storage/libmdbx-rs/src/error.rs index 2777aa653c..2ced5d355f 100644 --- a/crates/storage/libmdbx-rs/src/error.rs +++ b/crates/storage/libmdbx-rs/src/error.rs @@ -4,21 +4,42 @@ use std::{ffi::CStr, fmt, result, str}; /// An MDBX error kind. #[derive(Debug, thiserror::Error, Clone, PartialEq, Eq)] pub enum Error { + /// The key/value pair already exists. KeyExist, + /// The requested key/value pair was not found. NotFound, NoData, + /// The requested page was not found. PageNotFound, + /// The database is corrupted (e.g. a page was a wrong type) Corrupted, + /// The environment had a fatal error (e.g. failed to update a meta page) Panic, VersionMismatch, + /// File is not a valid MDBX file Invalid, + /// Environment map size reached. MapFull, + /// Environment reached the maximum number of databases. DbsFull, + /// Environment reached the maximum number of readers. ReadersFull, + /// The transaction has too many dirty pages (i.e. the transaction is too big). TxnFull, + /// The cursor stack is too deep. CursorFull, + /// The page does not have enough space. PageFull, - UnableExtendMapsize, + /// The database engine was unable to extend mapping, e.g. the address space is unavailable or + /// busy. + /// + /// This can mean: + /// - The database size was extended by other processes beyond the environment map size, and + /// the engine was unable to extend the mapping while starting a read transaction. The + /// environment should be re-opened to continue. + /// - The engine was unable to extend the mapping during a write transaction or an explicit + /// call to change the geometry of the environment. + UnableExtendMapSize, Incompatible, BadRslot, BadTxn, @@ -27,13 +48,14 @@ pub enum Error { Problem, Busy, Multival, + BadSignature, WannaRecovery, KeyMismatch, DecodeError, Access, TooLarge, DecodeErrorLenDiff, - Other(u32), + Other(i32), } impl Error { @@ -54,7 +76,7 @@ impl Error { ffi::MDBX_TXN_FULL => Error::TxnFull, ffi::MDBX_CURSOR_FULL => Error::CursorFull, ffi::MDBX_PAGE_FULL => Error::PageFull, - ffi::MDBX_UNABLE_EXTEND_MAPSIZE => Error::UnableExtendMapsize, + ffi::MDBX_UNABLE_EXTEND_MAPSIZE => Error::UnableExtendMapSize, ffi::MDBX_INCOMPATIBLE => Error::Incompatible, ffi::MDBX_BAD_RSLOT => Error::BadRslot, ffi::MDBX_BAD_TXN => Error::BadTxn, @@ -63,12 +85,13 @@ impl Error { ffi::MDBX_PROBLEM => Error::Problem, ffi::MDBX_BUSY => Error::Busy, ffi::MDBX_EMULTIVAL => Error::Multival, + ffi::MDBX_EBADSIGN => Error::BadSignature, ffi::MDBX_WANNA_RECOVERY => Error::WannaRecovery, ffi::MDBX_EKEYMISMATCH => Error::KeyMismatch, ffi::MDBX_EINVAL => Error::DecodeError, ffi::MDBX_EACCESS => Error::Access, ffi::MDBX_TOO_LARGE => Error::TooLarge, - other => Error::Other(other as u32), + other => Error::Other(other), } } @@ -88,7 +111,7 @@ impl Error { Error::TxnFull => ffi::MDBX_TXN_FULL, Error::CursorFull => ffi::MDBX_CURSOR_FULL, Error::PageFull => ffi::MDBX_PAGE_FULL, - Error::UnableExtendMapsize => ffi::MDBX_UNABLE_EXTEND_MAPSIZE, + Error::UnableExtendMapSize => ffi::MDBX_UNABLE_EXTEND_MAPSIZE, Error::Incompatible => ffi::MDBX_INCOMPATIBLE, Error::BadRslot => ffi::MDBX_BAD_RSLOT, Error::BadTxn => ffi::MDBX_BAD_TXN, @@ -102,7 +125,7 @@ impl Error { Error::DecodeError => ffi::MDBX_EINVAL, Error::Access => ffi::MDBX_EACCESS, Error::TooLarge => ffi::MDBX_TOO_LARGE, - Error::Other(err_code) => *err_code as i32, + Error::Other(err_code) => *err_code, _ => unreachable!(), }; err_code as u32 @@ -156,4 +179,9 @@ mod test { assert_eq!("MDBX_INVALID: File is not an MDBX file", Error::Invalid.to_string()); } + + #[test] + fn test_conversion() { + assert_eq!(Error::from_err_code(ffi::MDBX_KEYEXIST), Error::KeyExist); + } }