diff --git a/crates/nu-plugin/src/plugin/interface/plugin.rs b/crates/nu-plugin/src/plugin/interface/plugin.rs index a57d79b284..6e5b9dc5db 100644 --- a/crates/nu-plugin/src/plugin/interface/plugin.rs +++ b/crates/nu-plugin/src/plugin/interface/plugin.rs @@ -1037,11 +1037,21 @@ impl Interface for PluginInterface { fn write(&self, input: PluginInput) -> Result<(), ShellError> { log::trace!("to plugin: {:?}", input); - self.state.writer.write(&input) + self.state.writer.write(&input).map_err(|err| { + log::warn!("write() error: {}", err); + // If there's an error in the state, return that instead because it's likely more + // descriptive + self.state.error.get().cloned().unwrap_or(err) + }) } fn flush(&self) -> Result<(), ShellError> { - self.state.writer.flush() + self.state.writer.flush().map_err(|err| { + log::warn!("flush() error: {}", err); + // If there's an error in the state, return that instead because it's likely more + // descriptive + self.state.error.get().cloned().unwrap_or(err) + }) } fn stream_id_sequence(&self) -> &Sequence { diff --git a/crates/nu_plugin_stress_internals/src/main.rs b/crates/nu_plugin_stress_internals/src/main.rs index 78a94db5db..2ce2a5536e 100644 --- a/crates/nu_plugin_stress_internals/src/main.rs +++ b/crates/nu_plugin_stress_internals/src/main.rs @@ -82,6 +82,12 @@ pub fn main() -> Result<(), Box> { std::process::exit(1) } + // Read `Hello` message + let mut de = serde_json::Deserializer::from_reader(&mut input); + let hello: Value = Value::deserialize(&mut de)?; + + assert!(hello.get("Hello").is_some()); + // Send `Hello` message write( &mut output, @@ -103,12 +109,6 @@ pub fn main() -> Result<(), Box> { }), )?; - // Read `Hello` message - let mut de = serde_json::Deserializer::from_reader(&mut input); - let hello: Value = Value::deserialize(&mut de)?; - - assert!(hello.get("Hello").is_some()); - if opts.exit_early { // Exit without handling anything other than Hello std::process::exit(0);