Skip to content

Commit cfe80ac

Browse files
authored
output stderr in :sh popup if shell commands fail (#11239)
* refactor(commands): output `stderr` in `:sh` popup * refactor(commands): switch to `from_utf8_lossy` This way something is always displayed. * refactor: no longer log stderr output on failure
1 parent 63953e0 commit cfe80ac

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

helix-term/src/commands.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5716,27 +5716,24 @@ async fn shell_impl_async(
57165716
process.wait_with_output().await?
57175717
};
57185718

5719-
if !output.status.success() {
5720-
if !output.stderr.is_empty() {
5721-
let err = String::from_utf8_lossy(&output.stderr).to_string();
5722-
log::error!("Shell error: {}", err);
5723-
bail!("Shell error: {}", err);
5724-
}
5725-
match output.status.code() {
5726-
Some(exit_code) => bail!("Shell command failed: status {}", exit_code),
5727-
None => bail!("Shell command failed"),
5719+
let output = if !output.status.success() {
5720+
if output.stderr.is_empty() {
5721+
match output.status.code() {
5722+
Some(exit_code) => bail!("Shell command failed: status {}", exit_code),
5723+
None => bail!("Shell command failed"),
5724+
}
57285725
}
5726+
String::from_utf8_lossy(&output.stderr)
5727+
// Prioritize `stderr` output over `stdout`
57295728
} else if !output.stderr.is_empty() {
5730-
log::debug!(
5731-
"Command printed to stderr: {}",
5732-
String::from_utf8_lossy(&output.stderr).to_string()
5733-
);
5734-
}
5729+
let stderr = String::from_utf8_lossy(&output.stderr);
5730+
log::debug!("Command printed to stderr: {stderr}");
5731+
stderr
5732+
} else {
5733+
String::from_utf8_lossy(&output.stdout)
5734+
};
57355735

5736-
let str = std::str::from_utf8(&output.stdout)
5737-
.map_err(|_| anyhow!("Process did not output valid UTF-8"))?;
5738-
let tendril = Tendril::from(str);
5739-
Ok(tendril)
5736+
Ok(Tendril::from(output))
57405737
}
57415738

57425739
fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {

helix-term/src/commands/typed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2308,7 +2308,7 @@ fn run_shell_command(
23082308
));
23092309
compositor.replace_or_push("shell", popup);
23102310
}
2311-
editor.set_status("Command succeeded");
2311+
editor.set_status("Command run");
23122312
},
23132313
));
23142314
Ok(call)

0 commit comments

Comments
 (0)