From 202dfdaee24b982c7086ba5fa658540736a23dc5 Mon Sep 17 00:00:00 2001 From: Antoine Stevan <44101798+amtoine@users.noreply.github.com> Date: Wed, 9 Aug 2023 14:12:58 +0200 Subject: [PATCH] fix panic with `lines` on an error (#9967) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit should close https://github.com/nushell/nushell/issues/9965 # Description this PR implements the `todo!()` left in `lines`. # User-Facing Changes ### before ```nushell > open . | lines thread 'main' panicked at 'not yet implemented', crates/nu-command/src/filters/lines.rs:248:35 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` ### after ```nushell > open . | lines Error: nu::shell::io_error × I/O error help: Is a directory (os error 21) ``` # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :black_circle: `toolkit test` - :black_circle: `toolkit test stdlib` this PR adds the `lines_on_error` test to make sure this does not happen again :relieved: # After Submitting --- crates/nu-command/src/filters/lines.rs | 2 +- crates/nu-command/tests/commands/lines.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/src/filters/lines.rs b/crates/nu-command/src/filters/lines.rs index 31fbcf2c2..322d8a879 100644 --- a/crates/nu-command/src/filters/lines.rs +++ b/crates/nu-command/src/filters/lines.rs @@ -245,7 +245,7 @@ impl Iterator for RawStreamLinesAdapter { } } } - Err(_) => todo!(), + Err(err) => return Some(Err(err)), } } else { self.inner_complete = true; diff --git a/crates/nu-command/tests/commands/lines.rs b/crates/nu-command/tests/commands/lines.rs index ee8dc5881..2bfebbabf 100644 --- a/crates/nu-command/tests/commands/lines.rs +++ b/crates/nu-command/tests/commands/lines.rs @@ -61,3 +61,11 @@ fn lines_mixed_line_endings() { assert_eq!(actual.out, "3"); } + +#[cfg(not(windows))] +#[test] +fn lines_on_error() { + let actual = nu!("open . | lines"); + + assert!(actual.err.contains("Is a directory")); +}