Fix issues with error make refactor (#10950)

- Replaced one error return `None` with a `help` option.
- Fixed example.
- Added comments highlighting correct early returns.

Fix #10947
This commit is contained in:
Andrej Kolchin 2023-11-04 16:23:43 +00:00 committed by GitHub
parent 1a864ea6f4
commit f565661f42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -83,8 +83,8 @@ impl Command for ErrorMake {
start: 123 start: 123
end: 456 end: 456
} }
help: "A help string, suggesting a fix to the user" # optional
} }
help: "A help string, suggesting a fix to the user" # optional
}"#, }"#,
result: Some(Value::error( result: Some(Value::error(
ShellError::GenericError( ShellError::GenericError(
@ -160,6 +160,7 @@ fn make_other_error(value: &Value, throw_span: Option<Span>) -> ShellError {
let label = match value.get_data_by_key("label") { let label = match value.get_data_by_key("label") {
Some(value) => value, Some(value) => value,
// correct return: no label
None => { None => {
return ShellError::GenericError( return ShellError::GenericError(
msg, msg,
@ -215,7 +216,8 @@ fn make_other_error(value: &Value, throw_span: Option<Span>) -> ShellError {
Vec::new(), Vec::new(),
) )
} }
None => return ShellError::GenericError(msg, text, throw_span, None, Vec::new()), // correct return: label, no span
None => return ShellError::GenericError(msg, text, throw_span, help, Vec::new()),
}; };
let span_start = match get_span_sides(&span, "start") { let span_start = match get_span_sides(&span, "start") {
@ -237,6 +239,7 @@ fn make_other_error(value: &Value, throw_span: Option<Span>) -> ShellError {
); );
} }
// correct return: everything present
ShellError::GenericError( ShellError::GenericError(
msg, msg,
text, text,