Skip to content

Commit

Permalink
cli: translate last-minute EPIPE internally in handle_command_result()
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed Mar 2, 2024
1 parent ed1d2fd commit f76830a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 2 additions & 3 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 6 additions & 2 deletions cli/src/command_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit f76830a

Please sign in to comment.