Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,12 @@ pub enum MdbxError {
/// Permission defined
#[error("permission denied to setup database")]
Permission,
/// Unknown error code.
#[error("unknown error code: {0}")]
/// An error code MDBX did not map to a specific variant.
///
/// MDBX's own codes are negative; a positive code is a system `errno` (e.g. `ENOSPC` or
/// `EDQUOT`) that MDBX passed through unchanged, so it is rendered with its OS description
/// rather than a bare number.
#[error("{}", fmt_other_code(*.0))]
Other(i32),
/// Operation requires DUP_SORT flag on database.
#[error("operation requires DUP_SORT flag on database")]
Expand All @@ -193,6 +197,15 @@ pub enum MdbxError {
SnapshotDivergence,
}

// Positive codes are system errnos rendered via the OS; negatives are unrecognised MDBX codes.
fn fmt_other_code(code: i32) -> String {
if code > 0 {
std::io::Error::from_raw_os_error(code).to_string()
} else {
format!("unknown MDBX error code: {code}")
}
}

impl MdbxError {
/// Converts a raw error code to an [`MdbxError`].
pub const fn from_err_code(err_code: c_int) -> Self {
Expand Down