diff --git a/Cargo.toml b/Cargo.toml index 7c20fca9ef..3f4a858b67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -195,6 +195,11 @@ name = "cococo" path = "crates/nu-test-support/src/bins/cococo.rs" required-features = ["test-bins"] +[[bin]] +name = "nonu" +path = "crates/nu-test-support/src/bins/nonu.rs" +required-features = ["test-bins"] + # Core plugins that ship with `cargo install nu` by default # Currently, Cargo limits us to installing only one binary # unless we use [[bin]], so we use this as a workaround diff --git a/crates/nu-test-support/src/bins/nonu.rs b/crates/nu-test-support/src/bins/nonu.rs new file mode 100644 index 0000000000..4c1c4349f5 --- /dev/null +++ b/crates/nu-test-support/src/bins/nonu.rs @@ -0,0 +1,3 @@ +fn main() { + std::env::args().skip(1).for_each(|arg| print!("{}", arg)); +} diff --git a/src/commands/classified/external.rs b/src/commands/classified/external.rs index b6f2dbd097..c0cc3cc913 100644 --- a/src/commands/classified/external.rs +++ b/src/commands/classified/external.rs @@ -285,19 +285,27 @@ fn spawn( }; let file = futures::io::AllowStdIo::new(stdout); - let mut stream = FramedRead::new(file, LinesCodec).map(|line| { + let mut stream = FramedRead::new(file, LinesCodec); + + while let Some(line) = stream.next().await { if let Ok(line) = line { - Value { + yield Ok(Value { value: UntaggedValue::Primitive(Primitive::Line(line)), tag: name_tag.clone(), - } + }); } else { - panic!("Internal error: could not read lines of text from stdin") + yield Ok(Value { + value: UntaggedValue::Error( + ShellError::labeled_error( + "Unable to read lines from stdout. This usually happens when the output does not end with a newline.", + "unable to read from stdout", + &name_tag, + ) + ), + tag: name_tag.clone(), + }); + return; } - }); - - while let Some(item) = stream.next().await { - yield Ok(item) } } diff --git a/tests/shell/pipeline/commands/external.rs b/tests/shell/pipeline/commands/external.rs index 74a59b4b01..f26b3fe2ce 100644 --- a/tests/shell/pipeline/commands/external.rs +++ b/tests/shell/pipeline/commands/external.rs @@ -78,6 +78,24 @@ mod it_evaluation { } } +mod stdin_evaluation { + use super::nu_error; + use nu_test_support::pipeline; + + #[test] + fn does_not_panic_with_no_newline_in_stream() { + let stderr = nu_error!( + cwd: ".", + pipeline(r#" + nonu "where's the nuline?" + | count + "# + )); + + assert_eq!(stderr, ""); + } +} + mod external_words { use super::nu;