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

@ -277,10 +277,10 @@ fn at_impl(input: &[u8], arg: &Arguments, span: Span) -> Value {
match start.cmp(&end) {
Ordering::Equal => Value::Binary { val: vec![], span },
Ordering::Greater => Value::Error {
error: ShellError::TypeMismatch(
"End must be greater than or equal to Start".to_string(),
arg.arg_span,
),
error: ShellError::TypeMismatch {
err_message: "End must be greater than or equal to Start".to_string(),
span: arg.arg_span,
},
},
Ordering::Less => Value::Binary {
val: {

View File

@ -55,10 +55,10 @@ impl Command for BytesBuild {
// Explicitly propagate errors instead of dropping them.
Value::Error { error } => return Err(error),
other => {
return Err(ShellError::TypeMismatch(
"only binary data arguments are supported".to_string(),
other.expect_span(),
))
return Err(ShellError::TypeMismatch {
err_message: "only binary data arguments are supported".to_string(),
span: other.expect_span(),
})
}
}
}

View File

@ -61,10 +61,10 @@ impl Command for BytesRemove {
let cell_paths = (!cell_paths.is_empty()).then_some(cell_paths);
let pattern_to_remove = call.req::<Spanned<Vec<u8>>>(engine_state, stack, 0)?;
if pattern_to_remove.item.is_empty() {
return Err(ShellError::TypeMismatch(
"the pattern to remove cannot be empty".to_string(),
pattern_to_remove.span,
));
return Err(ShellError::TypeMismatch {
err_message: "the pattern to remove cannot be empty".to_string(),
span: pattern_to_remove.span,
});
}
let pattern_to_remove: Vec<u8> = pattern_to_remove.item;

View File

@ -61,10 +61,10 @@ impl Command for BytesReplace {
let cell_paths = (!cell_paths.is_empty()).then_some(cell_paths);
let find = call.req::<Spanned<Vec<u8>>>(engine_state, stack, 0)?;
if find.item.is_empty() {
return Err(ShellError::TypeMismatch(
"the pattern to find cannot be empty".to_string(),
find.span,
));
return Err(ShellError::TypeMismatch {
err_message: "the pattern to find cannot be empty".to_string(),
span: find.span,
});
}
let arg = Arguments {