From bfe9d8699d8b0fee9a7c570d7cd26f761054a76a Mon Sep 17 00:00:00 2001 From: Piepmatz Date: Sun, 13 Jul 2025 18:53:55 +0200 Subject: [PATCH] fix: unwrap `ShellErrorBridge` in `ByteStream::into_bytes` (#16161) - closes #16159 # Description The setup in #16159 produced a `ByteStream` that held the `ShellError` inside an `std::io::Error`. For exactly this setup is the `ShellErrorBridge` designed, while figuring out what happened I found out that inside `BytesStream::into_bytes` a sneaky `ShellErrorBridge` was hiding: image To fix this, I try to unwrap the bridge and if that is possible, return the original `ShellError`. This is done at multiple occasions inside `byte_stream.rs` already. With this fix, we get the original error that looks like this: image # User-Facing Changes None, just a better error. # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :green_circle: `toolkit test` - :green_circle: `toolkit test stdlib` # After Submitting To have less situations with other I/O errors, I opened #16160 to find out faster what other error was passed around. --- crates/nu-protocol/src/pipeline/byte_stream.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/nu-protocol/src/pipeline/byte_stream.rs b/crates/nu-protocol/src/pipeline/byte_stream.rs index 6684b51a35..4723a8134b 100644 --- a/crates/nu-protocol/src/pipeline/byte_stream.rs +++ b/crates/nu-protocol/src/pipeline/byte_stream.rs @@ -598,7 +598,12 @@ impl ByteStream { match self.stream { ByteStreamSource::Read(mut read) => { let mut buf = Vec::new(); - read.read_to_end(&mut buf).map_err(&from_io_error)?; + read.read_to_end(&mut buf).map_err(|err| { + match ShellErrorBridge::try_from(err) { + Ok(ShellErrorBridge(err)) => err, + Err(err) => ShellError::Io(from_io_error(err)), + } + })?; Ok(buf) } ByteStreamSource::File(mut file) => {