Skip to content

Commit 904f9dc

Browse files
committed
chore(driver): refactor error handling
1 parent fcf08d7 commit 904f9dc

File tree

1 file changed

+8
-28
lines changed

1 file changed

+8
-28
lines changed

src/driver.rs

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,35 +44,15 @@ pub async fn map_driver() -> Result<bool, MapDriverError> {
4444
let output = util::invoke_command(Command::new(kdmapper_path).arg(driver_path)).await?;
4545
let stdout = String::from_utf8_lossy(&output.stdout);
4646

47-
if stdout.contains("Device\\Nal is already in use") {
48-
return Err(MapDriverError::DeviceNalInUse);
47+
match stdout.as_ref() {
48+
s if s.contains("Device\\Nal is already in use") => Err(MapDriverError::DeviceNalInUse),
49+
s if s.contains("0xc0000603") => Err(MapDriverError::DriverBlocklist),
50+
s if s.contains("0xcf000001") => Err(MapDriverError::LogInitFailed),
51+
s if s.contains("0xcf000002") => Err(MapDriverError::PreInitFailed),
52+
s if s.contains("0xcf000003") => Err(MapDriverError::InitFailed),
53+
s if s.contains("[+] success") => Ok(!s.contains("0xcf000004")), // CSTATUS_DRIVER_ALREADY_LOADED
54+
s => Err(MapDriverError::Unknown(s.to_string())),
4955
}
50-
51-
if stdout.contains("0xc0000603") {
52-
return Err(MapDriverError::DriverBlocklist);
53-
}
54-
55-
if stdout.contains("0xcf000001") {
56-
return Err(MapDriverError::LogInitFailed);
57-
}
58-
59-
if stdout.contains("0xcf000002") {
60-
return Err(MapDriverError::PreInitFailed);
61-
}
62-
63-
if stdout.contains("0xcf000003") {
64-
return Err(MapDriverError::InitFailed);
65-
}
66-
67-
if stdout.contains("[+] success") && stdout.contains("0xcf000004") {
68-
return Ok(false);
69-
}
70-
71-
if stdout.contains("[+] success") {
72-
return Ok(true);
73-
}
74-
75-
return Err(MapDriverError::Unknown(stdout.to_string()));
7656
}
7757

7858
pub async fn map_driver_handled(http: &reqwest::Client) -> anyhow::Result<()> {

0 commit comments

Comments
 (0)