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

@ -63,10 +63,12 @@ impl Command for PluginDeclaration {
let mut child = plugin_cmd.spawn().map_err(|err| {
let decl = engine_state.get_decl(call.decl_id);
ShellError::SpannedLabeledError(
ShellError::GenericError(
format!("Unable to spawn plugin for {}", decl.name()),
format!("{}", err),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;
@ -94,10 +96,12 @@ impl Command for PluginDeclaration {
let response = self.encoding.decode_response(&mut buf_read).map_err(|err| {
let decl = engine_state.get_decl(call.decl_id);
ShellError::SpannedLabeledError(
ShellError::GenericError(
format!("Unable to decode call for {}", decl.name()),
err.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
});
@ -106,18 +110,22 @@ impl Command for PluginDeclaration {
Ok(PipelineData::Value(value.as_ref().clone(), None))
}
Ok(PluginResponse::Error(err)) => Err(err.into()),
Ok(PluginResponse::Signature(..)) => Err(ShellError::SpannedLabeledError(
Ok(PluginResponse::Signature(..)) => Err(ShellError::GenericError(
"Plugin missing value".into(),
"Received a signature from plugin instead of value".into(),
call.head,
Some(call.head),
None,
Vec::new(),
)),
Err(err) => Err(err),
}
} else {
Err(ShellError::SpannedLabeledError(
Err(ShellError::GenericError(
"Error with stdout reader".into(),
"no stdout reader".into(),
call.head,
Some(call.head),
None,
Vec::new(),
))
};

View File

@ -28,8 +28,16 @@ pub struct LabeledError {
impl From<LabeledError> for ShellError {
fn from(error: LabeledError) -> Self {
match error.span {
Some(span) => ShellError::SpannedLabeledError(error.label, error.msg, span),
None => ShellError::LabeledError(error.label, error.msg),
Some(span) => {
ShellError::GenericError(error.label, error.msg, Some(span), None, Vec::new())
}
None => ShellError::GenericError(
error.label,
"".to_string(),
None,
Some(error.msg),
Vec::new(),
),
}
}
}
@ -37,18 +45,10 @@ impl From<LabeledError> for ShellError {
impl From<ShellError> for LabeledError {
fn from(error: ShellError) -> Self {
match error {
ShellError::SpannedLabeledError(label, msg, span) => LabeledError {
label,
msg,
span: Some(span),
},
ShellError::LabeledError(label, msg) => LabeledError {
label,
msg,
span: None,
},
ShellError::CantConvert(expected, input, span)
| ShellError::CantConvertWithHelp(expected, input, span, _) => LabeledError {
ShellError::GenericError(label, msg, span, _help, _related) => {
LabeledError { label, msg, span }
}
ShellError::CantConvert(expected, input, span, _help) => LabeledError {
label: format!("Can't convert to {}", expected),
msg: format!("can't convert {} to {}", expected, input),
span: Some(span),