Document and critically review ShellError variants - Ep. 2 (#8326)

Continuation of #8229 

# Description

The `ShellError` enum at the moment is kind of messy. 

Many variants are basic tuple structs where you always have to reference
the implementation with its macro invocation to know which field serves
which purpose.
Furthermore we have both variants that are kind of redundant or either
overly broad to be useful for the user to match on or overly specific
with few uses.

So I set out to start fixing the lacking documentation and naming to
make it feasible to critically review the individual usages and fix
those.
Furthermore we can decide to join or split up variants that don't seem
to be fit for purpose.

**Everyone:** Feel free to add review comments if you spot inconsistent
use of `ShellError` variants.

- Name fields of `SE::IncorrectValue`
- Merge and name fields on `SE::TypeMismatch`
- Name fields on `SE::UnsupportedOperator`
- Name fields on `AssignmentRequires*` and fix doc
- Name fields on `SE::UnknownOperator`
- Name fields on `SE::MissingParameter`
- Name fields on `SE::DelimiterError`
- Name fields on `SE::IncompatibleParametersSingle`

# User-Facing Changes

(None now, end goal more explicit and consistent error messages)

# Tests + Formatting

(No additional tests needed so far)
This commit is contained in:
Stefan Holderbach
2023-03-06 11:31:07 +01:00
committed by GitHub
parent 4ae1b1cc26
commit f7b8f97873
60 changed files with 477 additions and 375 deletions

View File

@ -55,6 +55,6 @@ pub trait CustomValue: fmt::Debug + Send + Sync {
op: Span,
_right: &Value,
) -> Result<Value, ShellError> {
Err(ShellError::UnsupportedOperator(operator, op))
Err(ShellError::UnsupportedOperator { operator, span: op })
}
}

View File

@ -763,7 +763,7 @@ impl Value {
// Records (and tables) are the only built-in which support column names,
// so only use this message for them.
Value::Record { .. } => {
err_or_null!(ShellError::TypeMismatchGenericMessage {
err_or_null!(ShellError::TypeMismatch {
err_message: "Can't access record values with a row index. Try specifying a column name instead".into(),
span: *origin_span, }, *origin_span)
}
@ -2573,7 +2573,10 @@ impl Value {
&& (self.get_type() != Type::Any)
&& (rhs.get_type() != Type::Any)
{
return Err(ShellError::TypeMismatch("compatible type".to_string(), op));
return Err(ShellError::TypeMismatch {
err_message: "compatible type".to_string(),
span: op,
});
}
if let Some(ordering) = self.partial_cmp(rhs) {
@ -2606,7 +2609,10 @@ impl Value {
&& (self.get_type() != Type::Any)
&& (rhs.get_type() != Type::Any)
{
return Err(ShellError::TypeMismatch("compatible type".to_string(), op));
return Err(ShellError::TypeMismatch {
err_message: "compatible type".to_string(),
span: op,
});
}
self.partial_cmp(rhs)
@ -2637,7 +2643,10 @@ impl Value {
&& (self.get_type() != Type::Any)
&& (rhs.get_type() != Type::Any)
{
return Err(ShellError::TypeMismatch("compatible type".to_string(), op));
return Err(ShellError::TypeMismatch {
err_message: "compatible type".to_string(),
span: op,
});
}
self.partial_cmp(rhs)
@ -2668,7 +2677,10 @@ impl Value {
&& (self.get_type() != Type::Any)
&& (rhs.get_type() != Type::Any)
{
return Err(ShellError::TypeMismatch("compatible type".to_string(), op));
return Err(ShellError::TypeMismatch {
err_message: "compatible type".to_string(),
span: op,
});
}
match self.partial_cmp(rhs) {