Skip to content

Commit

Permalink
Fixes errors on command output
Browse files Browse the repository at this point in the history
The error occurs when the command output stream contains an invalid
UTF-8 character, or ends with a multi-bytes UTF-8 character.

Fixes #8110
  • Loading branch information
olivierlemasle committed Nov 5, 2023
1 parent 2c7d683 commit e57042a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
7 changes: 7 additions & 0 deletions .changes/fix-cmd-output-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@tauri-apps/cli": patch:bug
"tauri-cli": patch:bug
"tauri-bundler": patch:bug
---

Fixes errors on command output, occuring when the output stream contains an invalid UTF-8 character, or ends with a multi-bytes UTF-8 character.
16 changes: 10 additions & 6 deletions tooling/bundler/src/bundle/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,12 @@ impl CommandExt for Command {
let mut lines = stdout_lines_.lock().unwrap();
loop {
line.clear();
if let Ok(0) = stdout.read_line(&mut line) {
break;
match stdout.read_line(&mut line) {
Ok(0) => break,
Err(_) => continue,
_ => (),
}
debug!(action = "stdout"; "{}", &line[0..line.len() - 1]);
debug!(action = "stdout"; "{}", line.trim_end());
lines.extend(line.as_bytes().to_vec());
}
});
Expand All @@ -185,10 +187,12 @@ impl CommandExt for Command {
let mut lines = stderr_lines_.lock().unwrap();
loop {
line.clear();
if let Ok(0) = stderr.read_line(&mut line) {
break;
match stderr.read_line(&mut line) {
Ok(0) => break,
Err(_) => continue,
_ => (),
}
debug!(action = "stderr"; "{}", &line[0..line.len() - 1]);
debug!(action = "stderr"; "{}", line.trim_end());
lines.extend(line.as_bytes().to_vec());
}
});
Expand Down
16 changes: 10 additions & 6 deletions tooling/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,12 @@ impl CommandExt for Command {
let mut lines = stdout_lines_.lock().unwrap();
loop {
line.clear();
if let Ok(0) = stdout.read_line(&mut line) {
break;
match stdout.read_line(&mut line) {
Ok(0) => break,
Err(_) => continue,
_ => (),
}
debug!(action = "stdout"; "{}", &line[0..line.len() - 1]);
debug!(action = "stdout"; "{}", line.trim_end());
lines.extend(line.as_bytes().to_vec());
}
});
Expand All @@ -247,10 +249,12 @@ impl CommandExt for Command {
let mut lines = stderr_lines_.lock().unwrap();
loop {
line.clear();
if let Ok(0) = stderr.read_line(&mut line) {
break;
match stderr.read_line(&mut line) {
Ok(0) => break,
Err(_) => continue,
_ => (),
}
debug!(action = "stderr"; "{}", &line[0..line.len() - 1]);
debug!(action = "stderr"; "{}", line.trim_end());
lines.extend(line.as_bytes().to_vec());
}
});
Expand Down

0 comments on commit e57042a

Please sign in to comment.