use std::fmt;
#[derive(Debug, PartialEq)]
#[non_exhaustive]
pub enum BinaryError {
NoSentinel,
NoFuseVersion,
NoFuseLength,
FuseDoesNotExist(crate::Fuse),
UnknownFuse {
fuse: crate::Fuse,
value: u8,
},
#[allow(deprecated)]
NodeJsFlagNotPresent(crate::patcher::NodeJsCommandLineFlag),
ElectronOptionNotPresent(crate::patcher::ElectronOption),
#[allow(deprecated)]
MessageNotPresent(crate::patcher::DevToolsMessage),
}
impl fmt::Display for BinaryError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
BinaryError::NoSentinel => f.write_str("No fuse sentinel found"),
BinaryError::NoFuseVersion => f.write_str("Fuse had no version present"),
BinaryError::NoFuseLength => f.write_str("Fuse had no length specified"),
BinaryError::FuseDoesNotExist(fuse) => write!(f, "The {:?} fuse wasn't present", fuse),
BinaryError::UnknownFuse { fuse, value } => write!(
f,
"The {:?} fuse returned an unknown value of '{}'",
fuse, value
),
BinaryError::NodeJsFlagNotPresent(flag) => {
write!(f, "The {:?} debugging flag wasn't present", flag)
}
BinaryError::ElectronOptionNotPresent(opt) => {
write!(f, "The Electron option for {:?} wasn't present", opt)
}
BinaryError::MessageNotPresent(msg) => {
write!(f, "The DevTools message {:?} wasn't present", msg)
}
}
}
}
impl std::error::Error for BinaryError {}
#[derive(Debug, PartialEq)]
#[non_exhaustive]
pub enum PatcherError {
Binary(BinaryError),
FuseVersion {
expected: u8,
found: u8,
},
RemovedFuse(crate::Fuse),
}
impl From<BinaryError> for PatcherError {
fn from(e: BinaryError) -> Self {
PatcherError::Binary(e)
}
}
impl fmt::Display for PatcherError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PatcherError::Binary(e) => write!(f, "{}", e),
PatcherError::FuseVersion { expected, found } => write!(
f,
"Unknown fuse version found. Expected {}, but found {}",
expected, found
),
PatcherError::RemovedFuse(fuse) => write!(
f,
"Failed to modify the {:?} fuse because it is marked as removed",
fuse
),
}
}
}
impl std::error::Error for PatcherError {}