cli: translate last-minute EPIPE internally in handle_command_result()

This commit is contained in:
Yuya Nishihara 2024-03-02 14:07:41 +09:00
parent ed1d2fde27
commit f76830ab12
2 changed files with 8 additions and 5 deletions

View file

@ -74,7 +74,7 @@ use tracing_subscriber::prelude::*;
use crate::command_error::{
handle_command_result, internal_error, internal_error_with_message, user_error,
user_error_with_hint, user_error_with_message, CommandError, BROKEN_PIPE_EXIT_CODE,
user_error_with_hint, user_error_with_message, CommandError,
};
use crate::commit_templater::CommitTemplateLanguageExtension;
use crate::config::{
@ -2562,8 +2562,7 @@ 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);
let exit_code = handle_command_result(&mut ui, result)
.unwrap_or_else(|_| ExitCode::from(BROKEN_PIPE_EXIT_CODE));
let exit_code = handle_command_result(&mut ui, result);
ui.finalize_pager();
exit_code
}

View file

@ -436,9 +436,13 @@ impl From<GitIgnoreError> for CommandError {
}
}
pub(crate) const BROKEN_PIPE_EXIT_CODE: u8 = 3;
const BROKEN_PIPE_EXIT_CODE: u8 = 3;
pub(crate) fn handle_command_result(
pub(crate) fn handle_command_result(ui: &mut Ui, result: Result<(), CommandError>) -> ExitCode {
try_handle_command_result(ui, result).unwrap_or_else(|_| ExitCode::from(BROKEN_PIPE_EXIT_CODE))
}
fn try_handle_command_result(
ui: &mut Ui,
result: Result<(), CommandError>,
) -> io::Result<ExitCode> {