Skip to content

Commit

Permalink
fix(cli): Fixes errors on command output, closes #8110 (#8162)
Browse files Browse the repository at this point in the history
Fixes #8110
  • Loading branch information
olivierlemasle authored Nov 9, 2023
1 parent 416370a commit 1d5aa38
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 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.
22 changes: 14 additions & 8 deletions tooling/bundler/src/bundle/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,14 @@ 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,
Ok(_) => {
debug!(action = "stdout"; "{}", line.trim_end());
lines.extend(line.as_bytes().to_vec());
}
Err(_) => (),
}
debug!(action = "stdout"; "{}", &line[0..line.len() - 1]);
lines.extend(line.as_bytes().to_vec());
}
});

Expand All @@ -185,11 +188,14 @@ 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,
Ok(_) => {
debug!(action = "stderr"; "{}", line.trim_end());
lines.extend(line.as_bytes().to_vec());
}
Err(_) => (),
}
debug!(action = "stderr"; "{}", &line[0..line.len() - 1]);
lines.extend(line.as_bytes().to_vec());
}
});

Expand Down
22 changes: 14 additions & 8 deletions tooling/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,14 @@ 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,
Ok(_) => {
debug!(action = "stdout"; "{}", line.trim_end());
lines.extend(line.as_bytes().to_vec());
}
Err(_) => (),
}
debug!(action = "stdout"; "{}", &line[0..line.len() - 1]);
lines.extend(line.as_bytes().to_vec());
}
});

Expand All @@ -247,11 +250,14 @@ 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,
Ok(_) => {
debug!(action = "stderr"; "{}", line.trim_end());
lines.extend(line.as_bytes().to_vec());
}
Err(_) => (),
}
debug!(action = "stderr"; "{}", &line[0..line.len() - 1]);
lines.extend(line.as_bytes().to_vec());
}
});

Expand Down

0 comments on commit 1d5aa38

Please sign in to comment.