Convert Shellerror::GenericError to named fields (#11230)

# Description

Replace `.to_string()` used in `GenericError` with `.into()` as
`.into()` seems more popular

Replace `Vec::new()` used in `GenericError` with `vec![]` as `vec![]`
seems more popular

(There are so, so many)
This commit is contained in:
Eric Hodel
2023-12-06 15:40:03 -08:00
committed by GitHub
parent b03f1efac4
commit a95a4505ef
160 changed files with 2975 additions and 3228 deletions

View File

@ -150,18 +150,18 @@ fn convert_string_to_value(string_input: String, span: Span) -> Result<Value, Sh
nu_json::Error::Syntax(_, row, col) => {
let label = x.to_string();
let label_span = convert_row_column_to_span(row, col, &string_input);
Err(ShellError::GenericError(
"Error while parsing JSON text".into(),
"error parsing JSON text".into(),
Some(span),
None,
vec![ShellError::OutsideSpannedLabeledError(
Err(ShellError::GenericError {
error: "Error while parsing JSON text".into(),
msg: "error parsing JSON text".into(),
span: Some(span),
help: None,
inner: vec![ShellError::OutsideSpannedLabeledError(
string_input,
"Error while parsing JSON text".into(),
label,
label_span,
)],
))
})
}
x => Err(ShellError::CantConvert {
to_type: format!("structured json data ({x})"),

View File

@ -60,32 +60,32 @@ impl Command for FromNuon {
if let Some(pipeline) = block.pipelines.get(1) {
if let Some(element) = pipeline.elements.first() {
return Err(ShellError::GenericError(
"error when loading nuon text".into(),
"could not load nuon text".into(),
Some(head),
None,
vec![ShellError::OutsideSpannedLabeledError(
return Err(ShellError::GenericError {
error: "error when loading nuon text".into(),
msg: "could not load nuon text".into(),
span: Some(head),
help: None,
inner: vec![ShellError::OutsideSpannedLabeledError(
string_input,
"error when loading".into(),
"excess values when loading".into(),
element.span(),
)],
));
});
} else {
return Err(ShellError::GenericError(
"error when loading nuon text".into(),
"could not load nuon text".into(),
Some(head),
None,
vec![ShellError::GenericError(
"error when loading".into(),
"excess values when loading".into(),
Some(head),
None,
Vec::new(),
)],
));
return Err(ShellError::GenericError {
error: "error when loading nuon text".into(),
msg: "could not load nuon text".into(),
span: Some(head),
help: None,
inner: vec![ShellError::GenericError {
error: "error when loading".into(),
msg: "excess values when loading".into(),
span: Some(head),
help: None,
inner: vec![],
}],
});
}
}
@ -100,18 +100,18 @@ impl Command for FromNuon {
let mut pipeline = block.pipelines.remove(0);
if let Some(expr) = pipeline.elements.get(1) {
return Err(ShellError::GenericError(
"error when loading nuon text".into(),
"could not load nuon text".into(),
Some(head),
None,
vec![ShellError::OutsideSpannedLabeledError(
return Err(ShellError::GenericError {
error: "error when loading nuon text".into(),
msg: "could not load nuon text".into(),
span: Some(head),
help: None,
inner: vec![ShellError::OutsideSpannedLabeledError(
string_input,
"error when loading".into(),
"detected a pipeline in nuon file".into(),
expr.span(),
)],
));
});
}
if pipeline.elements.is_empty() {
@ -140,31 +140,31 @@ impl Command for FromNuon {
};
if let Some(err) = working_set.parse_errors.first() {
return Err(ShellError::GenericError(
"error when parsing nuon text".into(),
"could not parse nuon text".into(),
Some(head),
None,
vec![ShellError::OutsideSpannedLabeledError(
return Err(ShellError::GenericError {
error: "error when parsing nuon text".into(),
msg: "could not parse nuon text".into(),
span: Some(head),
help: None,
inner: vec![ShellError::OutsideSpannedLabeledError(
string_input,
"error when parsing".into(),
err.to_string(),
err.span(),
)],
));
});
}
let result = convert_to_value(expr, head, &string_input);
match result {
Ok(result) => Ok(result.into_pipeline_data_with_metadata(metadata)),
Err(err) => Err(ShellError::GenericError(
"error when loading nuon text".into(),
"could not load nuon text".into(),
Some(head),
None,
vec![err],
)),
Err(err) => Err(ShellError::GenericError {
error: "error when loading nuon text".into(),
msg: "could not load nuon text".into(),
span: Some(head),
help: None,
inner: vec![err],
}),
}
}
}