forked from extern/nushell
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:
@ -2654,9 +2654,12 @@ impl Value {
|
||||
&& (self.get_type() != Type::Any)
|
||||
&& (rhs.get_type() != Type::Any)
|
||||
{
|
||||
return Err(ShellError::TypeMismatch {
|
||||
err_message: "compatible type".to_string(),
|
||||
span: op,
|
||||
return Err(ShellError::OperatorMismatch {
|
||||
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)
|
||||
&& (rhs.get_type() != Type::Any)
|
||||
{
|
||||
return Err(ShellError::TypeMismatch {
|
||||
err_message: "compatible type".to_string(),
|
||||
span: op,
|
||||
return Err(ShellError::OperatorMismatch {
|
||||
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)
|
||||
&& (rhs.get_type() != Type::Any)
|
||||
{
|
||||
return Err(ShellError::TypeMismatch {
|
||||
err_message: "compatible type".to_string(),
|
||||
span: op,
|
||||
return Err(ShellError::OperatorMismatch {
|
||||
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)
|
||||
&& (rhs.get_type() != Type::Any)
|
||||
{
|
||||
return Err(ShellError::TypeMismatch {
|
||||
err_message: "compatible type".to_string(),
|
||||
span: op,
|
||||
return Err(ShellError::OperatorMismatch {
|
||||
op_span: op,
|
||||
lhs_ty: self.get_type(),
|
||||
lhs_span: self.span()?,
|
||||
rhs_ty: rhs.get_type(),
|
||||
rhs_span: rhs.span()?,
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user