update miette and switch to GenericErrors (#5222)

This commit is contained in:
Kat Marchán
2022-04-18 05:34:10 -07:00
committed by GitHub
parent cf65f77b02
commit 1314a87cb0
141 changed files with 1569 additions and 689 deletions

View File

@ -193,7 +193,7 @@ fn from_eml(
.with_body_preview(body_preview)
.parse()
.map_err(|_| {
ShellError::CantConvert("structured eml data".into(), "string".into(), head)
ShellError::CantConvert("structured eml data".into(), "string".into(), head, None)
})?;
let mut collected = IndexMap::new();

View File

@ -137,6 +137,7 @@ fn convert_nujson_to_value(value: &nu_json::Value, span: Span) -> Value {
"i64 sized integer".into(),
"value larger than i64".into(),
span,
None,
),
}
} else {
@ -188,10 +189,11 @@ 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::SpannedLabeledErrorRelated(
Err(ShellError::GenericError(
"Error while parsing JSON text".into(),
"error parsing JSON text".into(),
span,
Some(span),
None,
vec![ShellError::OutsideSpannedLabeledError(
string_input,
"Error while parsing JSON text".into(),
@ -204,6 +206,7 @@ fn convert_string_to_value(string_input: String, span: Span) -> Result<Value, Sh
format!("structured json data ({})", x),
"string".into(),
span,
None,
)),
},
}

View File

@ -95,10 +95,11 @@ impl Command for FromNuon {
if let Some(pipeline) = block.pipelines.get(1) {
if let Some(expr) = pipeline.expressions.get(0) {
return Err(ShellError::SpannedLabeledErrorRelated(
return Err(ShellError::GenericError(
"error when loading nuon text".into(),
"could not load nuon text".into(),
head,
Some(head),
None,
vec![ShellError::OutsideSpannedLabeledError(
string_input,
"error when loading".into(),
@ -107,14 +108,17 @@ impl Command for FromNuon {
)],
));
} else {
return Err(ShellError::SpannedLabeledErrorRelated(
return Err(ShellError::GenericError(
"error when loading nuon text".into(),
"could not load nuon text".into(),
head,
vec![ShellError::SpannedLabeledError(
Some(head),
None,
vec![ShellError::GenericError(
"error when loading".into(),
"excess values when loading".into(),
head,
Some(head),
None,
Vec::new(),
)],
));
}
@ -131,10 +135,11 @@ impl Command for FromNuon {
let mut pipeline = block.pipelines.remove(0);
if let Some(expr) = pipeline.expressions.get(1) {
return Err(ShellError::SpannedLabeledErrorRelated(
return Err(ShellError::GenericError(
"error when loading nuon text".into(),
"could not load nuon text".into(),
head,
Some(head),
None,
vec![ShellError::OutsideSpannedLabeledError(
string_input,
"error when loading".into(),
@ -157,10 +162,11 @@ impl Command for FromNuon {
};
if let Some(err) = error {
return Err(ShellError::SpannedLabeledErrorRelated(
return Err(ShellError::GenericError(
"error when parsing nuon text".into(),
"could not parse nuon text".into(),
head,
Some(head),
None,
vec![ShellError::OutsideSpannedLabeledError(
string_input,
"error when parsing".into(),
@ -174,10 +180,11 @@ impl Command for FromNuon {
match result {
Ok(result) => Ok(result.into_pipeline_data()),
Err(err) => Err(ShellError::SpannedLabeledErrorRelated(
Err(err) => Err(ShellError::GenericError(
"error when loading nuon text".into(),
"could not load nuon text".into(),
head,
Some(head),
None,
vec![err],
)),
}

View File

@ -124,6 +124,7 @@ pub fn convert_string_to_value(string_input: String, span: Span) -> Result<Value
"structured toml data".into(),
"string".into(),
span,
None,
)),
}
}

View File

@ -142,6 +142,7 @@ pub fn to_delimited_data(
format_name.into(),
value.get_type().to_string(),
value.span().unwrap_or(span),
None,
)),
}?;
Ok(Value::string(output, span).into_pipeline_data())

View File

@ -325,10 +325,12 @@ fn to_html(
let color_hm = match color_hm {
Ok(c) => c,
_ => {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Error finding theme name".to_string(),
"Error finding theme name".to_string(),
theme_span,
Some(theme_span),
None,
Vec::new(),
))
}
};

View File

@ -66,7 +66,12 @@ impl Command for ToJson {
}
.into_pipeline_data()),
_ => Ok(Value::Error {
error: ShellError::CantConvert("JSON".into(), value.get_type().to_string(), span),
error: ShellError::CantConvert(
"JSON".into(),
value.get_type().to_string(),
span,
None,
),
}
.into_pipeline_data()),
}

View File

@ -107,7 +107,7 @@ fn toml_into_pipeline_data(
}
.into_pipeline_data()),
_ => Ok(Value::Error {
error: ShellError::CantConvert("TOML".into(), value_type.to_string(), span),
error: ShellError::CantConvert("TOML".into(), value_type.to_string(), span, None),
}
.into_pipeline_data()),
}

View File

@ -68,6 +68,7 @@ fn to_url(input: PipelineData, head: Span) -> Result<PipelineData, ShellError> {
"URL".into(),
value.get_type().to_string(),
head,
None,
)),
}
}

View File

@ -118,10 +118,12 @@ pub fn write_xml_events<W: Write>(
for (k, v) in cols.iter().zip(vals.iter()) {
let mut e = BytesStart::owned(k.as_bytes(), k.len());
if !is_xml_row(v) {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Expected a row with 'children' and 'attributes' columns".to_string(),
"missing 'children' and 'attributes' columns ".to_string(),
span,
Some(span),
None,
Vec::new(),
));
}
let a = get_attributes(v, config);
@ -185,6 +187,7 @@ fn to_xml(
"XML".into(),
value_type.to_string(),
head,
None,
)),
}
}

View File

@ -103,7 +103,7 @@ fn to_yaml(input: PipelineData, head: Span) -> Result<PipelineData, ShellError>
}
.into_pipeline_data()),
_ => Ok(Value::Error {
error: ShellError::CantConvert("YAML".into(), value.get_type().to_string(), head),
error: ShellError::CantConvert("YAML".into(), value.get_type().to_string(), head, None),
}
.into_pipeline_data()),
}