mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 21:07:58 +02:00
Err message for sort-by invalid types now shows the mismatched types (#2366)
* make sort-by fail gracefully if mismatched types are compared * Added a test to check if sorted-by with invalid types exists gracefully * Linter changes * removed redundant pattern matching * Changed the error message * Added a comma after every argument * Changed the test to accomodate the new err messages * Err message for sort-by invalid types now shows the mismatched types * Lints problems * Changed unwrap to expect
This commit is contained in:
@ -135,13 +135,20 @@ pub fn sort(
|
||||
} => {
|
||||
let should_sort_case_insensitively = insensitive && vec.iter().all(|x| x.is_string());
|
||||
|
||||
if !vec
|
||||
if let Some(values) = vec
|
||||
.windows(2)
|
||||
.all(|elem| coerce_compare(&elem[0], &elem[1]).is_ok())
|
||||
.map(|elem| coerce_compare(&elem[0], &elem[1]))
|
||||
.find(|elem| elem.is_err())
|
||||
{
|
||||
let (type_1, type_2) = values
|
||||
.err()
|
||||
.expect("An error ocourred in the checking of types");
|
||||
return Err(ShellError::labeled_error(
|
||||
"Not all values can be compared",
|
||||
"not all values compare",
|
||||
format!(
|
||||
"Unable to sort values, as \"{}\" cannot compare against \"{}\"",
|
||||
type_1, type_2
|
||||
),
|
||||
tag,
|
||||
));
|
||||
}
|
||||
|
Reference in New Issue
Block a user