diff --git a/crates/nu-plugin/src/plugin/mod.rs b/crates/nu-plugin/src/plugin/mod.rs index 7ecaa0effd..1fb650309d 100644 --- a/crates/nu-plugin/src/plugin/mod.rs +++ b/crates/nu-plugin/src/plugin/mod.rs @@ -345,7 +345,10 @@ pub fn serve_plugin(plugin: &mut impl Plugin, encoder: impl PluginEncoder) { PluginResponse::PluginData(name, PluginData { data, span }) } Err(err) => PluginResponse::Error( - ShellError::PluginFailedToEncode(err.to_string()).into(), + ShellError::PluginFailedToEncode { + msg: err.to_string(), + } + .into(), ), }, value => PluginResponse::Value(Box::new(value)), diff --git a/crates/nu-plugin/src/protocol/mod.rs b/crates/nu-plugin/src/protocol/mod.rs index e74b350add..6a03604d04 100644 --- a/crates/nu-plugin/src/protocol/mod.rs +++ b/crates/nu-plugin/src/protocol/mod.rs @@ -88,7 +88,7 @@ impl From for LabeledError { msg, span: None, }, - ShellError::PluginFailedToEncode(msg) => LabeledError { + ShellError::PluginFailedToEncode { msg } => LabeledError { label: "Plugin failed to encode".into(), msg, span: None, diff --git a/crates/nu-plugin/src/serializers/json.rs b/crates/nu-plugin/src/serializers/json.rs index b37978e489..4944e943e3 100644 --- a/crates/nu-plugin/src/serializers/json.rs +++ b/crates/nu-plugin/src/serializers/json.rs @@ -17,16 +17,18 @@ impl PluginEncoder for JsonSerializer { plugin_call: &crate::protocol::PluginCall, writer: &mut impl std::io::Write, ) -> Result<(), nu_protocol::ShellError> { - serde_json::to_writer(writer, plugin_call) - .map_err(|err| ShellError::PluginFailedToEncode(err.to_string())) + serde_json::to_writer(writer, plugin_call).map_err(|err| ShellError::PluginFailedToEncode { + msg: err.to_string(), + }) } fn decode_call( &self, reader: &mut impl std::io::BufRead, ) -> Result { - serde_json::from_reader(reader) - .map_err(|err| ShellError::PluginFailedToEncode(err.to_string())) + serde_json::from_reader(reader).map_err(|err| ShellError::PluginFailedToEncode { + msg: err.to_string(), + }) } fn encode_response( @@ -34,16 +36,20 @@ impl PluginEncoder for JsonSerializer { plugin_response: &PluginResponse, writer: &mut impl std::io::Write, ) -> Result<(), ShellError> { - serde_json::to_writer(writer, plugin_response) - .map_err(|err| ShellError::PluginFailedToEncode(err.to_string())) + serde_json::to_writer(writer, plugin_response).map_err(|err| { + ShellError::PluginFailedToEncode { + msg: err.to_string(), + } + }) } fn decode_response( &self, reader: &mut impl std::io::BufRead, ) -> Result { - serde_json::from_reader(reader) - .map_err(|err| ShellError::PluginFailedToEncode(err.to_string())) + serde_json::from_reader(reader).map_err(|err| ShellError::PluginFailedToEncode { + msg: err.to_string(), + }) } } diff --git a/crates/nu-plugin/src/serializers/msgpack.rs b/crates/nu-plugin/src/serializers/msgpack.rs index 25dd63af51..b6b5776fd4 100644 --- a/crates/nu-plugin/src/serializers/msgpack.rs +++ b/crates/nu-plugin/src/serializers/msgpack.rs @@ -16,8 +16,11 @@ impl PluginEncoder for MsgPackSerializer { plugin_call: &crate::protocol::PluginCall, writer: &mut impl std::io::Write, ) -> Result<(), nu_protocol::ShellError> { - rmp_serde::encode::write(writer, plugin_call) - .map_err(|err| ShellError::PluginFailedToEncode(err.to_string())) + rmp_serde::encode::write(writer, plugin_call).map_err(|err| { + ShellError::PluginFailedToEncode { + msg: err.to_string(), + } + }) } fn decode_call( @@ -33,8 +36,11 @@ impl PluginEncoder for MsgPackSerializer { plugin_response: &PluginResponse, writer: &mut impl std::io::Write, ) -> Result<(), ShellError> { - rmp_serde::encode::write(writer, plugin_response) - .map_err(|err| ShellError::PluginFailedToEncode(err.to_string())) + rmp_serde::encode::write(writer, plugin_response).map_err(|err| { + ShellError::PluginFailedToEncode { + msg: err.to_string(), + } + }) } fn decode_response( diff --git a/crates/nu-protocol/src/shell_error.rs b/crates/nu-protocol/src/shell_error.rs index 6ff218411d..295e3ec931 100644 --- a/crates/nu-protocol/src/shell_error.rs +++ b/crates/nu-protocol/src/shell_error.rs @@ -745,9 +745,9 @@ pub enum ShellError { /// ## Resolution /// /// This is likely a bug with the plugin itself. - #[error("Plugin failed to encode: {0}")] + #[error("Plugin failed to encode: {msg}")] #[diagnostic(code(nu::shell::plugin_failed_to_encode))] - PluginFailedToEncode(String), + PluginFailedToEncode { msg: String }, /// A message to a plugin failed to decode. ///