cli: remove attempt to detect EPIPE caused by bad pager configuration

It turned out bad idea because EPIPE (or SIGPIPE) is kind of a successful
termination. We could show some warning based on pager exit code, but let's
avoid messing up again.

io::Error occurred in handle_command_result() is still mapped to a BrokenPipe.
panic()-ing there should be wrong.
This commit is contained in:
Yuya Nishihara 2023-02-15 09:53:09 +09:00
parent 91775fc4f6
commit 1bdee80a0d
2 changed files with 11 additions and 30 deletions

View File

@ -2151,21 +2151,9 @@ impl CliRunner {
let mut ui = Ui::with_config(&layered_configs.merge())
.expect("default config should be valid, env vars are stringly typed");
let result = self.run_internal(&mut ui, layered_configs);
match handle_command_result(&mut ui, result) {
Ok(exit_code) => {
ui.finalize_pager();
exit_code
}
Err(err) => {
// The error is most likely a BrokenPipe. If the pager is closed by user
// (by e.g. pressing "q"), BrokenPipe shouldn't be considered a hard error.
// Otherwise, close pager and report the error to stderr.
let success_or_not_paged = ui.finalize_pager();
if !success_or_not_paged {
writeln!(ui.error(), "Error: {err}").ok();
}
ExitCode::from(BROKEN_PIPE_EXIT_CODE)
}
}
let exit_code = handle_command_result(&mut ui, result)
.unwrap_or_else(|_| ExitCode::from(BROKEN_PIPE_EXIT_CODE));
ui.finalize_pager();
exit_code
}
}

View File

@ -247,27 +247,20 @@ impl Ui {
}
}
/// Waits for the pager exits. Returns true if the pager exits successfully
/// or the output isn't paged.
pub fn finalize_pager(&mut self) -> bool {
/// Waits for the pager exits.
pub fn finalize_pager(&mut self) {
if let UiOutput::Paged {
mut child,
child_stdin,
} = mem::replace(&mut self.output, UiOutput::new_terminal())
{
drop(child_stdin);
match child.wait() {
Ok(status) => status.success(),
Err(e) => {
// It's possible (though unlikely) that this write fails, but
// this function gets called so late that there's not much we
// can do about it.
writeln!(self.error(), "Failed to wait on pager: {e}").ok();
false
}
if let Err(e) = child.wait() {
// It's possible (though unlikely) that this write fails, but
// this function gets called so late that there's not much we
// can do about it.
writeln!(self.error(), "Failed to wait on pager: {e}").ok();
}
} else {
true
}
}