use std::{
error::Error,
ffi::NulError,
fmt::{self, Display},
io,
str::Utf8Error,
};
#[derive(Debug)]
pub enum LibcryptErr {
IOError(io::Error),
UuidError(uuid::Error),
NullError(NulError),
Utf8Error(Utf8Error),
JsonError(serde_json::Error),
InvalidConversion,
NullPtr,
NoNull(&'static str),
Other(String),
}
impl Display for LibcryptErr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
LibcryptErr::IOError(ref e) => write!(f, "IO error occurred: {e}"),
LibcryptErr::UuidError(ref e) => write!(f, "Failed to parse UUID from C string: {e}"),
LibcryptErr::NullError(ref e) => {
write!(f, "Null error occurred when handling &str conversion: {e}")
}
LibcryptErr::Utf8Error(ref e) => {
write!(f, "UTF8 error occurred when handling &str conversion: {e}")
}
LibcryptErr::JsonError(ref e) => {
write!(f, "Failed to parse the provided string into JSON: {e}")
}
LibcryptErr::InvalidConversion => {
write!(f, "Failed to perform the specified conversion")
}
LibcryptErr::NullPtr => write!(f, "Cryptsetup returned a null pointer"),
LibcryptErr::NoNull(s) => {
write!(f, "Static string {s} was not created with c_str!() macro")
}
LibcryptErr::Other(ref s) => write!(f, "Failed with error: {s}"),
}
}
}
impl Error for LibcryptErr {}