mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-19 03:04:27 -05:00
chore: decode MDBX error code (#21766)
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user