mirror of
https://github.com/nushell/nushell.git
synced 2025-03-26 07:19:55 +01: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:
parent
b01cbf82c3
commit
a1840e9d20
@ -98,11 +98,17 @@ impl Command for Histogram {
|
|||||||
let frequency_name_arg = call.opt::<Spanned<String>>(engine_state, stack, 1)?;
|
let frequency_name_arg = call.opt::<Spanned<String>>(engine_state, stack, 1)?;
|
||||||
let frequency_column_name = match frequency_name_arg {
|
let frequency_column_name = match frequency_name_arg {
|
||||||
Some(inner) => {
|
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 {
|
return Err(ShellError::TypeMismatch {
|
||||||
err_message:
|
err_message: format!(
|
||||||
"frequency-column-name can't be 'value', 'count' or 'percentage'"
|
"frequency-column-name can't be {}",
|
||||||
.to_string(),
|
forbidden_column_names
|
||||||
|
.iter()
|
||||||
|
.map(|val| format!("'{}'", val))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ")
|
||||||
|
),
|
||||||
span: inner.span,
|
span: inner.span,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2654,9 +2654,12 @@ impl Value {
|
|||||||
&& (self.get_type() != Type::Any)
|
&& (self.get_type() != Type::Any)
|
||||||
&& (rhs.get_type() != Type::Any)
|
&& (rhs.get_type() != Type::Any)
|
||||||
{
|
{
|
||||||
return Err(ShellError::TypeMismatch {
|
return Err(ShellError::OperatorMismatch {
|
||||||
err_message: "compatible type".to_string(),
|
op_span: op,
|
||||||
span: op,
|
lhs_ty: self.get_type(),
|
||||||
|
lhs_span: self.span()?,
|
||||||
|
rhs_ty: rhs.get_type(),
|
||||||
|
rhs_span: rhs.span()?,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2690,9 +2693,12 @@ impl Value {
|
|||||||
&& (self.get_type() != Type::Any)
|
&& (self.get_type() != Type::Any)
|
||||||
&& (rhs.get_type() != Type::Any)
|
&& (rhs.get_type() != Type::Any)
|
||||||
{
|
{
|
||||||
return Err(ShellError::TypeMismatch {
|
return Err(ShellError::OperatorMismatch {
|
||||||
err_message: "compatible type".to_string(),
|
op_span: op,
|
||||||
span: op,
|
lhs_ty: self.get_type(),
|
||||||
|
lhs_span: self.span()?,
|
||||||
|
rhs_ty: rhs.get_type(),
|
||||||
|
rhs_span: rhs.span()?,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2724,9 +2730,12 @@ impl Value {
|
|||||||
&& (self.get_type() != Type::Any)
|
&& (self.get_type() != Type::Any)
|
||||||
&& (rhs.get_type() != Type::Any)
|
&& (rhs.get_type() != Type::Any)
|
||||||
{
|
{
|
||||||
return Err(ShellError::TypeMismatch {
|
return Err(ShellError::OperatorMismatch {
|
||||||
err_message: "compatible type".to_string(),
|
op_span: op,
|
||||||
span: op,
|
lhs_ty: self.get_type(),
|
||||||
|
lhs_span: self.span()?,
|
||||||
|
rhs_ty: rhs.get_type(),
|
||||||
|
rhs_span: rhs.span()?,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2758,9 +2767,12 @@ impl Value {
|
|||||||
&& (self.get_type() != Type::Any)
|
&& (self.get_type() != Type::Any)
|
||||||
&& (rhs.get_type() != Type::Any)
|
&& (rhs.get_type() != Type::Any)
|
||||||
{
|
{
|
||||||
return Err(ShellError::TypeMismatch {
|
return Err(ShellError::OperatorMismatch {
|
||||||
err_message: "compatible type".to_string(),
|
op_span: op,
|
||||||
span: op,
|
lhs_ty: self.get_type(),
|
||||||
|
lhs_span: self.span()?,
|
||||||
|
rhs_ty: rhs.get_type(),
|
||||||
|
rhs_span: rhs.span()?,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user