electron_hardener/
error.rs1use std::fmt;
2
3#[derive(Debug, PartialEq)]
6#[non_exhaustive]
7pub enum BinaryError {
8 NoSentinel,
12 NoFuseVersion,
14 NoFuseLength,
16 FuseDoesNotExist(crate::Fuse),
18 UnknownFuse {
23 fuse: crate::Fuse,
25 value: u8,
27 },
28 #[allow(deprecated)]
29 NodeJsFlagNotPresent(crate::patcher::NodeJsCommandLineFlag),
31 ElectronOptionNotPresent(crate::patcher::ElectronOption),
33 #[allow(deprecated)]
34 MessageNotPresent(crate::patcher::DevToolsMessage),
36}
37
38impl fmt::Display for BinaryError {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 match self {
41 BinaryError::NoSentinel => f.write_str("No fuse sentinel found"),
42 BinaryError::NoFuseVersion => f.write_str("Fuse had no version present"),
43 BinaryError::NoFuseLength => f.write_str("Fuse had no length specified"),
44 BinaryError::FuseDoesNotExist(fuse) => write!(f, "The {:?} fuse wasn't present", fuse),
45 BinaryError::UnknownFuse { fuse, value } => write!(
46 f,
47 "The {:?} fuse returned an unknown value of '{}'",
48 fuse, value
49 ),
50 BinaryError::NodeJsFlagNotPresent(flag) => {
51 write!(f, "The {:?} debugging flag wasn't present", flag)
52 }
53 BinaryError::ElectronOptionNotPresent(opt) => {
54 write!(f, "The Electron option for {:?} wasn't present", opt)
55 }
56 BinaryError::MessageNotPresent(msg) => {
57 write!(f, "The DevTools message {:?} wasn't present", msg)
58 }
59 }
60 }
61}
62
63impl std::error::Error for BinaryError {}
64
65#[derive(Debug, PartialEq)]
67#[non_exhaustive]
68pub enum PatcherError {
69 Binary(BinaryError),
71 FuseVersion {
73 expected: u8,
75 found: u8,
77 },
78 RemovedFuse(crate::Fuse),
82}
83
84impl From<BinaryError> for PatcherError {
85 fn from(e: BinaryError) -> Self {
86 PatcherError::Binary(e)
87 }
88}
89
90impl fmt::Display for PatcherError {
91 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
92 match self {
93 PatcherError::Binary(e) => write!(f, "{}", e),
94 PatcherError::FuseVersion { expected, found } => write!(
95 f,
96 "Unknown fuse version found. Expected {}, but found {}",
97 expected, found
98 ),
99 PatcherError::RemovedFuse(fuse) => write!(
100 f,
101 "Failed to modify the {:?} fuse because it is marked as removed",
102 fuse
103 ),
104 }
105 }
106}
107
108impl std::error::Error for PatcherError {}