mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
Improve CantFindColumn and ColumnAlreadyExists errors (#7164)
* Improve CantFindColumn and ColumnAlreadyExists errors * Update tests
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user