forked from extern/nushell
Convert PluginFailedToDecode to named fields (#11126)
# Description Part of #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:
parent
d5677625a7
commit
776df7cd93
@ -326,7 +326,9 @@ pub fn serve_plugin(plugin: &mut impl Plugin, encoder: impl PluginEncoder) {
|
||||
.map(|custom_value| {
|
||||
Value::custom_value(custom_value, plugin_data.span)
|
||||
})
|
||||
.map_err(|err| ShellError::PluginFailedToDecode(err.to_string()))
|
||||
.map_err(|err| ShellError::PluginFailedToDecode {
|
||||
msg: err.to_string(),
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
@ -362,7 +364,9 @@ pub fn serve_plugin(plugin: &mut impl Plugin, encoder: impl PluginEncoder) {
|
||||
}
|
||||
PluginCall::CollapseCustomValue(plugin_data) => {
|
||||
let response = bincode::deserialize::<Box<dyn CustomValue>>(&plugin_data.data)
|
||||
.map_err(|err| ShellError::PluginFailedToDecode(err.to_string()))
|
||||
.map_err(|err| ShellError::PluginFailedToDecode {
|
||||
msg: err.to_string(),
|
||||
})
|
||||
.and_then(|val| val.to_base_value(plugin_data.span))
|
||||
.map(Box::new)
|
||||
.map_err(LabeledError::from)
|
||||
|
@ -93,7 +93,7 @@ impl From<ShellError> for LabeledError {
|
||||
msg,
|
||||
span: None,
|
||||
},
|
||||
ShellError::PluginFailedToDecode(msg) => LabeledError {
|
||||
ShellError::PluginFailedToDecode { msg } => LabeledError {
|
||||
label: "Plugin failed to decode".into(),
|
||||
msg,
|
||||
span: None,
|
||||
|
@ -27,8 +27,9 @@ impl PluginEncoder for MsgPackSerializer {
|
||||
&self,
|
||||
reader: &mut impl std::io::BufRead,
|
||||
) -> Result<crate::protocol::PluginCall, nu_protocol::ShellError> {
|
||||
rmp_serde::from_read(reader)
|
||||
.map_err(|err| ShellError::PluginFailedToDecode(err.to_string()))
|
||||
rmp_serde::from_read(reader).map_err(|err| ShellError::PluginFailedToDecode {
|
||||
msg: err.to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
fn encode_response(
|
||||
@ -47,8 +48,9 @@ impl PluginEncoder for MsgPackSerializer {
|
||||
&self,
|
||||
reader: &mut impl std::io::BufRead,
|
||||
) -> Result<PluginResponse, ShellError> {
|
||||
rmp_serde::from_read(reader)
|
||||
.map_err(|err| ShellError::PluginFailedToDecode(err.to_string()))
|
||||
rmp_serde::from_read(reader).map_err(|err| ShellError::PluginFailedToDecode {
|
||||
msg: err.to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -754,9 +754,9 @@ pub enum ShellError {
|
||||
/// ## Resolution
|
||||
///
|
||||
/// This is either an issue with the inputs to a plugin (bad JSON?) or a bug in the plugin itself. Fix or report as appropriate.
|
||||
#[error("Plugin failed to decode: {0}")]
|
||||
#[error("Plugin failed to decode: {msg}")]
|
||||
#[diagnostic(code(nu::shell::plugin_failed_to_decode))]
|
||||
PluginFailedToDecode(String),
|
||||
PluginFailedToDecode { msg: String },
|
||||
|
||||
/// I/O operation interrupted.
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user