Convert remainder of ShellError variants to named fields (#11276)

# Description

Removed variants that are no longer in use:
* `NoFile*`
* `UnexpectedAbbrComponent`

Converted:
* `OutsideSpannedLabeledError`
* `EvalBlockWithInput`
* `Break`
* `Continue`
* `Return`
* `NotAConstant`
* `NotAConstCommand`
* `NotAConstHelp`
* `InvalidGlobPattern`
* `ErrorExpandingGlob`

Fixes #10700 

# User-Facing Changes

None

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

N/A
This commit is contained in:
Eric Hodel
2023-12-09 16:46:21 -08:00
committed by GitHub
parent ca05553fc6
commit 3e5f81ae14
22 changed files with 328 additions and 298 deletions

View File

@ -27,7 +27,7 @@ impl Command for Break {
call: &Call,
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
Err(ShellError::Break(call.head))
Err(ShellError::Break { span: call.head })
}
fn examples(&self) -> Vec<Example> {

View File

@ -27,7 +27,7 @@ impl Command for Continue {
call: &Call,
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
Err(ShellError::Continue(call.head))
Err(ShellError::Continue { span: call.head })
}
fn examples(&self) -> Vec<Example> {

View File

@ -113,10 +113,10 @@ impl Command for For {
redirect_stdout,
redirect_stderr,
) {
Err(ShellError::Break(_)) => {
Err(ShellError::Break { .. }) => {
break;
}
Err(ShellError::Continue(_)) => {
Err(ShellError::Continue { .. }) => {
continue;
}
Err(err) => {
@ -159,10 +159,10 @@ impl Command for For {
redirect_stdout,
redirect_stderr,
) {
Err(ShellError::Break(_)) => {
Err(ShellError::Break { .. }) => {
break;
}
Err(ShellError::Continue(_)) => {
Err(ShellError::Continue { .. }) => {
continue;
}
Err(err) => {

View File

@ -48,10 +48,10 @@ impl Command for Loop {
call.redirect_stdout,
call.redirect_stderr,
) {
Err(ShellError::Break(_)) => {
Err(ShellError::Break { .. }) => {
break;
}
Err(ShellError::Continue(_)) => {
Err(ShellError::Continue { .. }) => {
continue;
}
Err(err) => {

View File

@ -42,12 +42,15 @@ impl Command for Return {
) -> Result<PipelineData, ShellError> {
let return_value: Option<Value> = call.opt(engine_state, stack, 0)?;
if let Some(value) = return_value {
Err(ShellError::Return(call.head, Box::new(value)))
Err(ShellError::Return {
span: call.head,
value: Box::new(value),
})
} else {
Err(ShellError::Return(
call.head,
Box::new(Value::nothing(call.head)),
))
Err(ShellError::Return {
span: call.head,
value: Box::new(Value::nothing(call.head)),
})
}
}

View File

@ -128,9 +128,9 @@ fn handle_catch(
/// `Err` when flow control to bubble up with `?`
fn intercept_block_control(error: ShellError) -> Result<ShellError, ShellError> {
match error {
nu_protocol::ShellError::Break(_) => Err(error),
nu_protocol::ShellError::Continue(_) => Err(error),
nu_protocol::ShellError::Return(_, _) => Err(error),
nu_protocol::ShellError::Break { .. } => Err(error),
nu_protocol::ShellError::Continue { .. } => Err(error),
nu_protocol::ShellError::Return { .. } => Err(error),
_ => Ok(error),
}
}

View File

@ -62,10 +62,10 @@ impl Command for While {
call.redirect_stdout,
call.redirect_stderr,
) {
Err(ShellError::Break(_)) => {
Err(ShellError::Break { .. }) => {
break;
}
Err(ShellError::Continue(_)) => {
Err(ShellError::Continue { .. }) => {
continue;
}
Err(err) => {