mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
libguestfs: Rust binding build error and warning fixes
Internal error type did not implement the necessary traits to be treated as a proper Rust error. This would cause ergonomic issues with manual error handling and with error handling crates like anyhow. Implement the Display and Error trait for internal Error type. This also fixes the build warnings. Signed-off-by: Jacob Reger <regerjacob@gmail.com>
This commit is contained in:
committed by
Richard W.M. Jones
parent
d7d5264ce8
commit
f81444ccad
@@ -46,6 +46,42 @@ pub enum Error {
|
||||
Create,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Error::API(err) => {
|
||||
write!(
|
||||
f,
|
||||
"API Error:\n\tOperation: {}\n\tMessage: {}\n\tError Number: {}",
|
||||
err.operation, err.message, err.errno
|
||||
)
|
||||
}
|
||||
Error::IllegalString(err) => {
|
||||
write!(
|
||||
f,
|
||||
"Illegal string Error:\nNull byte found\n\tDetails: {}",
|
||||
err
|
||||
)
|
||||
}
|
||||
Error::Utf8Error(err) => {
|
||||
write!(
|
||||
f,
|
||||
"Utf8 Error:\nFailed to interpret string as utf-8\n\tDetails: {}",
|
||||
err
|
||||
)
|
||||
}
|
||||
Error::UnixError(err, op) => {
|
||||
write!(f, "Unix Error:\n\tError: {}\n\tOperation: {}", err, op)
|
||||
}
|
||||
Error::Create => {
|
||||
write!(f, "Creation Error:\nFailed to create a guestfs handle")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
impl convert::From<ffi::NulError> for Error {
|
||||
fn from(error: ffi::NulError) -> Self {
|
||||
Error::IllegalString(error)
|
||||
|
||||
Reference in New Issue
Block a user