Skip to content

Commit

Permalink
fix(packager): avoid crashing on invalid utf8 from shell commands
Browse files Browse the repository at this point in the history
  • Loading branch information
amr-crabnebula committed Dec 1, 2023
1 parent f04c17f commit 2d780cc
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions crates/packager/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,31 @@ impl CommandExt for Command {
let stdout_lines = Arc::new(Mutex::new(Vec::new()));
let stdout_lines_ = stdout_lines.clone();
std::thread::spawn(move || {
let mut buf = String::new();
let mut buf = Vec::new();
let mut lines = stdout_lines_.lock().unwrap();
loop {
buf.clear();
if let Ok(0) = stdout.read_line(&mut buf) {
if let Ok(0) = stdout.read_until(b'\n', &mut buf) {
break;
}
tracing::debug!("{}", &buf[0..buf.len() - 1]);
lines.extend(buf.as_bytes());
tracing::debug!("{}", String::from_utf8_lossy(&buf[..buf.len() - 1]));
lines.extend(&buf);
}
});

let mut stderr = child.stderr.take().map(BufReader::new).unwrap();
let stderr_lines = Arc::new(Mutex::new(Vec::new()));
let stderr_lines_ = stderr_lines.clone();
std::thread::spawn(move || {
let mut buf = String::new();
let mut buf = Vec::new();
let mut lines = stderr_lines_.lock().unwrap();
loop {
buf.clear();
if let Ok(0) = stderr.read_line(&mut buf) {
if let Ok(0) = stderr.read_until(b'\n', &mut buf) {
break;
}
tracing::debug!("{}", &buf[0..buf.len() - 1]);
lines.extend(buf.as_bytes());
tracing::debug!("{}", String::from_utf8_lossy(&buf[..buf.len() - 1]));
lines.extend(&buf);
}
});

Expand Down

0 comments on commit 2d780cc

Please sign in to comment.