chore: decode MDBX error code (#21766)

This commit is contained in:
DaniPopes
2026-02-03 21:16:32 +01:00
committed by GitHub
parent 648f19fb56
commit 87bae74094

View File

@@ -133,7 +133,7 @@ pub enum Error {
#[error("permission denied to setup database")]
Permission,
/// Unknown error code.
#[error("unknown error code: {0}")]
#[error("{}", Error::fmt_other(*.0))]
Other(i32),
}
@@ -215,6 +215,13 @@ impl Error {
Self::Other(err_code) => *err_code,
}
}
fn fmt_other(code: i32) -> String {
let mut s = String::with_capacity(1024);
let desc = unsafe { ffi::mdbx_strerror_r(code, s.as_mut_ptr().cast(), 1024) };
let desc = unsafe { std::ffi::CStr::from_ptr(desc) }.to_string_lossy();
desc.into_owned()
}
}
impl From<Error> for i32 {