fix: Exit without flushing stdout and stderr

Standard out is flushed during `std::rt::cleanup()`, called by
`std::process::exit()`, and standard error is unbuffered, so doesn't
need to be flushed.
This commit is contained in:
Casey Rodarmor 2024-06-19 21:00:37 -07:00
parent 9c1153d6b4
commit 90b2661ad0
2 changed files with 2 additions and 11 deletions

View file

@ -23,7 +23,7 @@ use crate::output::fmt::Colorizer;
use crate::output::fmt::Stream;
use crate::parser::features::suggestions;
use crate::util::FlatMap;
use crate::util::{color::ColorChoice, safe_exit, SUCCESS_CODE, USAGE_CODE};
use crate::util::{color::ColorChoice, SUCCESS_CODE, USAGE_CODE};
use crate::Command;
#[cfg(feature = "error-context")]
@ -233,7 +233,7 @@ impl<F: ErrorFormatter> Error<F> {
pub fn exit(&self) -> ! {
// Swallow broken pipe errors
let _ = self.print();
safe_exit(self.exit_code())
std::process::exit(self.exit_code());
}
/// Prints formatted and colored error to `stdout` or `stderr` according to its error kind

View file

@ -29,15 +29,6 @@ pub(crate) const SUCCESS_CODE: i32 = 0;
// - Python's `argparse` returns 2
pub(crate) const USAGE_CODE: i32 = 2;
pub(crate) fn safe_exit(code: i32) -> ! {
use std::io::Write;
let _ = std::io::stdout().lock().flush();
let _ = std::io::stderr().lock().flush();
std::process::exit(code)
}
#[cfg(not(feature = "unicode"))]
pub(crate) fn eq_ignore_case(left: &str, right: &str) -> bool {
left.eq_ignore_ascii_case(right)