Skip to content

Commit ce43742

Browse files
author
Claude DevOps Engineer
committed
Replace String::from_utf8().unwrap() with from_utf8_lossy()
Prevent panics on non-UTF-8 stderr output in invoke_script() (macOS) and run_command() (Linux) by using String::from_utf8_lossy() which replaces invalid sequences with the Unicode replacement character. Closes #19
1 parent 2020c76 commit ce43742

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/linux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn run_command(command: &str, args: &[&str]) -> ShutdownResult {
5959
}
6060
Err(Error::new(
6161
ErrorKind::Other,
62-
String::from_utf8(output.stderr).unwrap(),
62+
String::from_utf8_lossy(&output.stderr).into_owned(),
6363
))
6464
}
6565
Err(error) => Err(error),

src/macos.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn invoke_script(script: &str) -> ShutdownResult {
1515
}
1616
Err(Error::new(
1717
ErrorKind::Other,
18-
String::from_utf8(output.stderr).unwrap(),
18+
String::from_utf8_lossy(&output.stderr).into_owned(),
1919
))
2020
}
2121
Err(error) => Err(error),

0 commit comments

Comments
 (0)