mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
join: flush stdout before final error message
This commit is contained in:
parent
bf67c5d981
commit
b873d46ca0
2 changed files with 17 additions and 21 deletions
|
@ -28,7 +28,7 @@ static NAME: &str = "join";
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum JoinError {
|
enum JoinError {
|
||||||
IOError(std::io::Error),
|
IOError(std::io::Error),
|
||||||
UnorderedInput,
|
UnorderedInput(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UError for JoinError {
|
impl UError for JoinError {
|
||||||
|
@ -43,7 +43,7 @@ impl Display for JoinError {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
JoinError::IOError(e) => write!(f, "io error: {}", e),
|
JoinError::IOError(e) => write!(f, "io error: {}", e),
|
||||||
JoinError::UnorderedInput => Ok(()),
|
JoinError::UnorderedInput(e) => f.write_str(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -538,24 +538,22 @@ impl<'a> State<'a> {
|
||||||
|
|
||||||
let diff = input.compare(self.get_current_key(), line.get_field(self.key));
|
let diff = input.compare(self.get_current_key(), line.get_field(self.key));
|
||||||
|
|
||||||
if diff == Ordering::Greater {
|
if diff == Ordering::Greater
|
||||||
if input.check_order == CheckOrder::Enabled
|
&& (input.check_order == CheckOrder::Enabled
|
||||||
|| (self.has_unpaired && !self.has_failed)
|
|| (self.has_unpaired && !self.has_failed))
|
||||||
{
|
{
|
||||||
eprintln!(
|
let err_msg = format!(
|
||||||
"{}: {}:{}: is not sorted: {}",
|
"{}:{}: is not sorted: {}",
|
||||||
uucore::execution_phrase(),
|
self.file_name.maybe_quote(),
|
||||||
self.file_name.maybe_quote(),
|
self.line_num,
|
||||||
self.line_num,
|
String::from_utf8_lossy(&line.string)
|
||||||
String::from_utf8_lossy(&line.string)
|
);
|
||||||
);
|
|
||||||
|
|
||||||
self.has_failed = true;
|
|
||||||
}
|
|
||||||
// This is fatal if the check is enabled.
|
// This is fatal if the check is enabled.
|
||||||
if input.check_order == CheckOrder::Enabled {
|
if input.check_order == CheckOrder::Enabled {
|
||||||
return Err(JoinError::UnorderedInput);
|
return Err(JoinError::UnorderedInput(err_msg));
|
||||||
}
|
}
|
||||||
|
eprintln!("{}: {}", uucore::execution_phrase(), err_msg);
|
||||||
|
self.has_failed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Some(line))
|
Ok(Some(line))
|
||||||
|
|
|
@ -339,8 +339,7 @@ fn wrong_line_order() {
|
||||||
.fails()
|
.fails()
|
||||||
.stdout_does_not_contain("7 g f 4 fg")
|
.stdout_does_not_contain("7 g f 4 fg")
|
||||||
.stderr_is(&format!(
|
.stderr_is(&format!(
|
||||||
"{0} {1}: fields_4.txt:5: is not sorted: 11 g 5 gh",
|
"{0}: fields_4.txt:5: is not sorted: 11 g 5 gh",
|
||||||
ts.bin_path.to_string_lossy(),
|
|
||||||
ts.util_name
|
ts.util_name
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -366,8 +365,7 @@ fn both_files_wrong_line_order() {
|
||||||
.fails()
|
.fails()
|
||||||
.stdout_does_not_contain("5 e 3 ef")
|
.stdout_does_not_contain("5 e 3 ef")
|
||||||
.stderr_is(&format!(
|
.stderr_is(&format!(
|
||||||
"{0} {1}: fields_5.txt:4: is not sorted: 3",
|
"{0}: fields_5.txt:4: is not sorted: 3",
|
||||||
ts.bin_path.to_string_lossy(),
|
|
||||||
ts.util_name
|
ts.util_name
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue