mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 11:05:40 +02:00
Improve CantFindColumn and ColumnAlreadyExists errors (#7164)
* Improve CantFindColumn and ColumnAlreadyExists errors * Update tests
This commit is contained in:
@ -250,6 +250,7 @@ pub fn group(
|
||||
move |_, row: &Value| match row.get_data_by_key(&column_name.item) {
|
||||
Some(group_key) => Ok(group_key.as_string()?),
|
||||
None => Err(ShellError::CantFindColumn(
|
||||
column_name.item.to_string(),
|
||||
column_name.span,
|
||||
row.span().unwrap_or(column_name.span),
|
||||
)),
|
||||
|
@ -137,6 +137,7 @@ pub fn split_by(
|
||||
});
|
||||
Ok(split(&splitter, input, name)?)
|
||||
}
|
||||
// This uses the same format as the 'requires a column name' error in sort_utils.rs
|
||||
None => Err(ShellError::GenericError(
|
||||
"expected name".into(),
|
||||
"requires a column name for splitting".into(),
|
||||
@ -165,6 +166,7 @@ pub fn split(
|
||||
move |_, row: &Value| match row.get_data_by_key(&column_name.item) {
|
||||
Some(group_key) => Ok(group_key.as_string()?),
|
||||
None => Err(ShellError::CantFindColumn(
|
||||
column_name.item.to_string(),
|
||||
column_name.span,
|
||||
row.span().unwrap_or(column_name.span),
|
||||
)),
|
||||
|
@ -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