Convert ShellError::UnsupportedInput to named fields (#10971)

# Description

This is easy to do with rust-analyzer, but I didn't want to just pump
these all out without feedback.

Part of #10700

# User-Facing Changes

None

# Tests + Formatting

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

# After Submitting

N/A

---------

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
This commit is contained in:
Eric Hodel
2023-11-07 14:25:32 -08:00
committed by GitHub
parent 45b02ce2ab
commit 7a3cbf43e8
56 changed files with 506 additions and 567 deletions

View File

@ -627,12 +627,14 @@ pub enum ShellError {
/// This error is fairly generic. Refer to the specific error message for further details.
#[error("Unsupported input")]
#[diagnostic(code(nu::shell::unsupported_input))]
UnsupportedInput(
String,
String,
#[label("{0}")] Span, // call head (the name of the command itself)
#[label("input type: {1}")] Span,
),
UnsupportedInput {
msg: String,
input: String,
#[label("{msg}")]
msg_span: Span,
#[label("{input}")]
input_span: Span,
},
/// Failed to parse an input into a datetime value.
///

View File

@ -1659,12 +1659,12 @@ impl Value {
// SIGH...
Value::Error { error, .. } => return Err(*error.clone()),
_ => {
return Err(ShellError::UnsupportedInput(
"expected table or record".into(),
format!("input type: {:?}", val.get_type()),
head_span,
*span,
))
return Err(ShellError::UnsupportedInput {
msg: "expected table or record".into(),
input: format!("input type: {:?}", val.get_type()),
msg_span: head_span,
input_span: *span,
})
}
}
}
@ -1697,12 +1697,12 @@ impl Value {
*self = record
}
other => {
return Err(ShellError::UnsupportedInput(
"table or record".into(),
format!("input type: {:?}", other.get_type()),
head_span,
*span,
))
return Err(ShellError::UnsupportedInput {
msg: "table or record".into(),
input: format!("input type: {:?}", other.get_type()),
msg_span: head_span,
input_span: *span,
})
}
},
PathMember::Int {
@ -3220,27 +3220,24 @@ impl Value {
if let Some(regex) = cache.get(rhs) {
regex.is_match(lhs)
} else {
let regex = Regex::new(rhs).map_err(|e| {
ShellError::UnsupportedInput(
format!("{e}"),
"value originated from here".into(),
span,
rhs_span,
)
})?;
let regex =
Regex::new(rhs).map_err(|e| ShellError::UnsupportedInput {
msg: format!("{e}"),
input: "value originated from here".into(),
msg_span: span,
input_span: rhs_span,
})?;
let ret = regex.is_match(lhs);
cache.put(rhs.clone(), regex);
ret
}
}
Err(_) => {
let regex = Regex::new(rhs).map_err(|e| {
ShellError::UnsupportedInput(
format!("{e}"),
"value originated from here".into(),
span,
rhs_span,
)
let regex = Regex::new(rhs).map_err(|e| ShellError::UnsupportedInput {
msg: format!("{e}"),
input: "value originated from here".into(),
msg_span: span,
input_span: rhs_span,
})?;
regex.is_match(lhs)
}