Improve CantFindColumn and ColumnAlreadyExists errors (#7164)

* Improve CantFindColumn and ColumnAlreadyExists errors

* Update tests
This commit is contained in:
Leon
2022-11-20 03:35:55 +10:00
committed by GitHub
parent 41f72b1236
commit 4b83a2d27a
8 changed files with 131 additions and 37 deletions

View File

@ -1,5 +1,5 @@
use alphanumeric_sort::compare_str;
use nu_engine::column::column_does_not_exist;
use nu_engine::column::nonexistent_column;
use nu_protocol::{ShellError, Span, Value};
use std::cmp::Ordering;
@ -81,12 +81,18 @@ pub fn sort(
..
} => {
if sort_columns.is_empty() {
println!("sort-by requires a column name to sort table data");
return Err(ShellError::CantFindColumn(span, span));
// This uses the same format as the 'requires a column name' error in split_by.rs
return Err(ShellError::GenericError(
"expected name".into(),
"requires a column name to sort table data".into(),
Some(span),
None,
Vec::new(),
));
}
if column_does_not_exist(sort_columns.clone(), cols.to_vec()) {
return Err(ShellError::CantFindColumn(span, span));
if let Some(nonexistent) = nonexistent_column(sort_columns.clone(), cols.to_vec()) {
return Err(ShellError::CantFindColumn(nonexistent, span, span));
}
// check to make sure each value in each column in the record