Skip to content

Commit

Permalink
Merge pull request #176 from jbaublitz/error-code
Browse files Browse the repository at this point in the history
Add error code to libblkid error variant
  • Loading branch information
jbaublitz authored Dec 18, 2024
2 parents 35ae0e9 + 76fe77a commit 6ed2ddc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub enum BlkidErr {
/// An unspecified error type and an error message providing more information
Other(String),
/// An error code was returned by libblkid
LibErr,
LibErr(i64),
}

impl Display for BlkidErr {
Expand All @@ -72,7 +72,7 @@ impl Display for BlkidErr {
BlkidErr::IO(ref e) => write!(f, "An IO error occurred: {e}"),
BlkidErr::Uuid(ref e) => write!(f, "A UUID error occurred: {e}"),
BlkidErr::Other(ref s) => write!(f, "{s}"),
BlkidErr::LibErr => write!(f, "libblkid returned an error code indicating an operation could not be completed successfully"),
BlkidErr::LibErr(code) => write!(f, "libblkid returned an error code indicating an operation could not be completed successfully: {code}"),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ macro_rules! errno {
($ret_expr:expr) => {
match $ret_expr {
i if i == 0 => Ok(()),
i if i < 0 => Err($crate::err::BlkidErr::LibErr),
i if i < 0 => Err($crate::err::BlkidErr::LibErr(i64::from(i))),
_ => Err($crate::err::BlkidErr::PositiveReturnCode),
}
};
Expand All @@ -34,7 +34,7 @@ macro_rules! errno_ptr {
($ret_expr:expr) => {{
let ptr = $ret_expr;
if ptr.is_null() {
Err($crate::err::BlkidErr::LibErr)
Err($crate::err::BlkidErr::LibErr(0))
} else {
Ok(ptr)
}
Expand All @@ -55,7 +55,7 @@ macro_rules! option_ptr {
macro_rules! errno_with_ret {
($ret_expr:expr) => {
match $ret_expr {
i if i < 0 => Err($crate::err::BlkidErr::LibErr),
i if i < 0 => Err($crate::err::BlkidErr::LibErr(i64::from(i))),
i => Ok(i),
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl BlkidProbe {
pub fn do_safeprobe(&mut self) -> Result<BlkidSafeprobeRet> {
let ret = unsafe { libblkid_rs_sys::blkid_do_safeprobe(self.0) };
if ret == -1 {
Err(BlkidErr::LibErr)
Err(BlkidErr::LibErr(-1))
} else {
Ok(BlkidSafeprobeRet::try_from(ret)?)
}
Expand Down
8 changes: 4 additions & 4 deletions src/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ pub fn parse_tag_string(tag_string: &str) -> Result<(String, String)> {
let tag_cstring = CString::new(tag_string)?;
let mut type_: *mut c_char = ptr::null_mut();
let mut value: *mut c_char = ptr::null_mut();
if unsafe {
let ret = unsafe {
libblkid_rs_sys::blkid_parse_tag_string(
tag_cstring.as_ptr(),
&mut type_ as *mut *mut _,
&mut value as *mut *mut _,
)
} < 0
{
Err(BlkidErr::LibErr)
};
if ret < 0 {
Err(BlkidErr::LibErr(i64::from(ret)))
} else {
assert!(!type_.is_null() && !value.is_null());
let type_str = unsafe { CStr::from_ptr(type_) };
Expand Down

0 comments on commit 6ed2ddc

Please sign in to comment.