-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: give more helpful error when trying to get a column that is missing from only some rows #14811
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -595,6 +595,19 @@ pub enum ShellError { | |
src_span: Span, | ||
}, | ||
|
||
/// Not all rows contain data in the requested column. | ||
/// | ||
/// ## Resolution | ||
/// | ||
/// Use the Optional Operator, --ignore-errors with get or select, or fill in the missing values. | ||
#[error("Not all rows contain a value for '{col_name}'")] | ||
#[diagnostic(code(nu::shell::row_lacks_value))] | ||
RowLacksValue { | ||
col_name: String, | ||
#[label = "try using '{col_name}?'"] | ||
span: Option<Span>, | ||
Comment on lines
+607
to
+608
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This points to the cell path component (if that is set correctly in all circumstances) Question if we should have another label pointing to the source |
||
}, | ||
|
||
/// Attempted to insert a column into a table, but a column with that name already exists. | ||
/// | ||
/// ## Resolution | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1252,9 +1252,22 @@ impl Value { | |
}), | ||
} | ||
}) | ||
.collect::<Result<_, _>>()?; | ||
.collect::<Vec<Result<_, _>>>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't collect all the
Instead of a raw non-short-circuiting collect, we should replace the
|
||
|
||
current = Value::list(list, span); | ||
let missing_col_errors = list | ||
.iter() | ||
.filter(|row| matches!(row, Err(ShellError::CantFindColumn { .. }))) | ||
.count(); | ||
|
||
if missing_col_errors != 0 && missing_col_errors < list.len() { | ||
return Err(ShellError::RowLacksValue { | ||
col_name: column_name.clone(), | ||
span: Some(*origin_span), | ||
}); | ||
} | ||
|
||
current = | ||
Value::list(list.into_iter().collect::<Result<_, _>>()?, span); | ||
} | ||
Value::Custom { ref val, .. } => { | ||
current = match val.follow_path_string( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment only appears in the Rust crate documentation. If you want to show it you can use the
miette
#[help]
attribute.As
follow_cell_path
and friends are also used in a bunch other commands , you should check that the error message like that makes universal sense, including its span annotations.