diff --git a/src/uu/join/src/join.rs b/src/uu/join/src/join.rs index 861d1684a..e5abefba4 100644 --- a/src/uu/join/src/join.rs +++ b/src/uu/join/src/join.rs @@ -28,7 +28,7 @@ static NAME: &str = "join"; #[derive(Debug)] enum JoinError { IOError(std::io::Error), - UnorderedInput, + UnorderedInput(String), } impl UError for JoinError { @@ -43,7 +43,7 @@ impl Display for JoinError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { 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)); - if diff == Ordering::Greater { - if input.check_order == CheckOrder::Enabled - || (self.has_unpaired && !self.has_failed) - { - eprintln!( - "{}: {}:{}: is not sorted: {}", - uucore::execution_phrase(), - self.file_name.maybe_quote(), - self.line_num, - String::from_utf8_lossy(&line.string) - ); - - self.has_failed = true; - } + if diff == Ordering::Greater + && (input.check_order == CheckOrder::Enabled + || (self.has_unpaired && !self.has_failed)) + { + let err_msg = format!( + "{}:{}: is not sorted: {}", + self.file_name.maybe_quote(), + self.line_num, + String::from_utf8_lossy(&line.string) + ); // This is fatal if the check is 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)) diff --git a/tests/by-util/test_join.rs b/tests/by-util/test_join.rs index dbc0bf411..d5da873f6 100644 --- a/tests/by-util/test_join.rs +++ b/tests/by-util/test_join.rs @@ -339,8 +339,7 @@ fn wrong_line_order() { .fails() .stdout_does_not_contain("7 g f 4 fg") .stderr_is(&format!( - "{0} {1}: fields_4.txt:5: is not sorted: 11 g 5 gh", - ts.bin_path.to_string_lossy(), + "{0}: fields_4.txt:5: is not sorted: 11 g 5 gh", ts.util_name )); } @@ -366,8 +365,7 @@ fn both_files_wrong_line_order() { .fails() .stdout_does_not_contain("5 e 3 ef") .stderr_is(&format!( - "{0} {1}: fields_5.txt:4: is not sorted: 3", - ts.bin_path.to_string_lossy(), + "{0}: fields_5.txt:4: is not sorted: 3", ts.util_name )); }