mirror of
https://github.com/nushell/nushell.git
synced 2024-11-23 00:43:33 +01: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:
parent
57101d5022
commit
1d5518a214
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -1,5 +1,15 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "Inflector"
|
||||
version = "0.11.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3"
|
||||
dependencies = [
|
||||
"lazy_static 1.4.0",
|
||||
"regex 1.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "addr2line"
|
||||
version = "0.13.0"
|
||||
@ -2956,6 +2966,7 @@ dependencies = [
|
||||
name = "nu-cli"
|
||||
version = "0.18.2"
|
||||
dependencies = [
|
||||
"Inflector",
|
||||
"ansi_term 0.12.1",
|
||||
"app_dirs2",
|
||||
"async-recursion",
|
||||
|
@ -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,
|
||||
));
|
||||
}
|
||||
|
@ -57,7 +57,9 @@ fn by_invalid_types() {
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("Not all values can be compared"));
|
||||
assert!(actual.err.contains("not all values compare"));
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("Unable to sort values, as \"integer\" cannot compare against \"string\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user