mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
fix: fixed typo and improved Value TypeMismatch exceptions (#8324)
# Description This PR aims to improve `TypeMismatch` exception that occurs when comparing two values with `<`, `>`, `<=` or `>=` operators. *Before*  *After*  This PR also bundles a small refactor for histogram forbidden column names exception, previous implementation forgot a column name in the message, to avoid this, I'm re-using the same array for checking and error display # User-Facing Changes Not much changes except a better and more readable exception for the user # Tests + Formatting Does not break any tests, formatting passes as well :)
This commit is contained in:
@ -98,11 +98,17 @@ impl Command for Histogram {
|
||||
let frequency_name_arg = call.opt::<Spanned<String>>(engine_state, stack, 1)?;
|
||||
let frequency_column_name = match frequency_name_arg {
|
||||
Some(inner) => {
|
||||
if ["value", "count", "quantile", "percentage"].contains(&inner.item.as_str()) {
|
||||
let forbidden_column_names = ["value", "count", "quantile", "percentage"];
|
||||
if forbidden_column_names.contains(&inner.item.as_str()) {
|
||||
return Err(ShellError::TypeMismatch {
|
||||
err_message:
|
||||
"frequency-column-name can't be 'value', 'count' or 'percentage'"
|
||||
.to_string(),
|
||||
err_message: format!(
|
||||
"frequency-column-name can't be {}",
|
||||
forbidden_column_names
|
||||
.iter()
|
||||
.map(|val| format!("'{}'", val))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
),
|
||||
span: inner.span,
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user