1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use std::fmt;
#[derive(Debug, PartialEq)]
#[non_exhaustive]
pub enum BinaryError {
NoSentinel,
NoFuseVersion,
NoFuseLength,
FuseDoesNotExist(crate::Fuse),
UnknownFuse {
fuse: crate::Fuse,
value: u8,
},
NodeJsFlagNotPresent(crate::patcher::NodeJsCommandLineFlag),
ElectronOptionNotPresent(crate::patcher::ElectronOption),
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 {}