diff --git a/crates/nu-command/src/filesystem/open.rs b/crates/nu-command/src/filesystem/open.rs index 65892faa11..5d53e2d612 100644 --- a/crates/nu-command/src/filesystem/open.rs +++ b/crates/nu-command/src/filesystem/open.rs @@ -121,7 +121,11 @@ impl Command for Open { let buf_reader = BufReader::new(file); let output = PipelineData::RawStream( - RawStream::new(Box::new(BufferedReader { input: buf_reader }), ctrlc), + RawStream::new( + Box::new(BufferedReader { input: buf_reader }), + ctrlc, + call_span, + ), call_span, None, ); diff --git a/crates/nu-command/src/network/fetch.rs b/crates/nu-command/src/network/fetch.rs index 68b04b1e93..993077a56b 100644 --- a/crates/nu-command/src/network/fetch.rs +++ b/crates/nu-command/src/network/fetch.rs @@ -362,6 +362,7 @@ fn response_to_buffer( input: buffered_input, }), engine_state.ctrlc.clone(), + span, ), span, None, diff --git a/crates/nu-command/src/strings/str_/collect.rs b/crates/nu-command/src/strings/str_/collect.rs index 783fef4ebb..3881ca54cd 100644 --- a/crates/nu-command/src/strings/str_/collect.rs +++ b/crates/nu-command/src/strings/str_/collect.rs @@ -42,11 +42,18 @@ impl Command for StrCollect { // let output = input.collect_string(&separator.unwrap_or_default(), &config)?; // Hmm, not sure what we actually want. If you don't use debug_string, Date comes out as human readable // which feels funny - #[allow(clippy::needless_collect)] - let strings: Vec = input - .into_iter() - .map(|value| value.debug_string("\n", &config)) - .collect(); + let mut strings: Vec = vec![]; + + for value in input { + match value { + Value::Error { error } => { + return Err(error); + } + value => { + strings.push(value.debug_string("\n", &config)); + } + } + } let output = if let Some(separator) = separator { strings.join(&separator) diff --git a/crates/nu-command/src/system/run_external.rs b/crates/nu-command/src/system/run_external.rs index 4c2ad078dc..c8d7afa47b 100644 --- a/crates/nu-command/src/system/run_external.rs +++ b/crates/nu-command/src/system/run_external.rs @@ -243,7 +243,7 @@ impl ExternalCommand { let receiver = ChannelReceiver::new(rx); Ok(PipelineData::RawStream( - RawStream::new(Box::new(receiver), output_ctrlc), + RawStream::new(Box::new(receiver), output_ctrlc, head), head, None, )) diff --git a/crates/nu-command/src/viewers/table.rs b/crates/nu-command/src/viewers/table.rs index 2014ca5fd7..38f181a7f5 100644 --- a/crates/nu-command/src/viewers/table.rs +++ b/crates/nu-command/src/viewers/table.rs @@ -72,6 +72,7 @@ impl Command for Table { .into_iter(), ), ctrlc, + head, ), head, None, @@ -187,6 +188,7 @@ impl Command for Table { stream, }), ctrlc, + head, ), head, None, diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index 8794a30760..ae81a9dbb9 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -175,11 +175,14 @@ impl Value { Value::Binary { val, .. } => Ok(match std::str::from_utf8(val) { Ok(s) => s.to_string(), Err(_) => { + // println!("{:?}", e); + // println!("bytes: {}", pretty_hex::pretty_hex(&val)); + // panic!("let's see it"); return Err(ShellError::CantConvert( - "binary".into(), "string".into(), + "binary".into(), self.span()?, - )) + )); } }), x => Err(ShellError::CantConvert( @@ -203,8 +206,8 @@ impl Value { }, Err(_) => { return Err(ShellError::CantConvert( - "binary".into(), "string".into(), + "binary".into(), self.span()?, )) } @@ -299,7 +302,7 @@ impl Value { match self { Value::Int { val, .. } => Ok(*val), x => Err(ShellError::CantConvert( - "float".into(), + "integer".into(), x.get_type().to_string(), self.span()?, )), diff --git a/crates/nu-protocol/src/value/stream.rs b/crates/nu-protocol/src/value/stream.rs index f45985bc8b..7478b7c221 100644 --- a/crates/nu-protocol/src/value/stream.rs +++ b/crates/nu-protocol/src/value/stream.rs @@ -19,13 +19,14 @@ impl RawStream { pub fn new( stream: Box, ShellError>> + Send + 'static>, ctrlc: Option>, + span: Span, ) -> Self { Self { stream, leftover: vec![], ctrlc, is_binary: false, - span: Span::new(0, 0), + span, } } @@ -63,8 +64,10 @@ impl Iterator for RawStream { match self.stream.next() { Some(buffer) => match buffer { Ok(mut v) => { - while let Some(b) = self.leftover.pop() { - v.insert(0, b); + if !self.leftover.is_empty() { + while let Some(b) = self.leftover.pop() { + v.insert(0, b); + } } Some(Ok(Value::Binary { val: v, @@ -81,8 +84,10 @@ impl Iterator for RawStream { match self.stream.next() { Some(buffer) => match buffer { Ok(mut v) => { - while let Some(b) = self.leftover.pop() { - v.insert(0, b); + if !self.leftover.is_empty() { + while let Some(b) = self.leftover.pop() { + v.insert(0, b); + } } match String::from_utf8(v.clone()) { @@ -113,8 +118,7 @@ impl Iterator for RawStream { // Okay, we have a tiny bit of error at the end of the buffer. This could very well be // a character that spans two frames. Since this is the case, remove the error from // the current frame an dput it in the leftover buffer. - self.leftover = - v[(err.utf8_error().valid_up_to() + 1)..].to_vec(); + self.leftover = v[err.utf8_error().valid_up_to()..].to_vec(); let buf = v[0..err.utf8_error().valid_up_to()].to_vec(); diff --git a/src/main.rs b/src/main.rs index a1ce83ae0d..8363b8e379 100644 --- a/src/main.rs +++ b/src/main.rs @@ -120,7 +120,11 @@ fn main() -> Result<()> { let buf_reader = BufReader::new(stdin); PipelineData::RawStream( - RawStream::new(Box::new(BufferedReader::new(buf_reader)), Some(ctrlc)), + RawStream::new( + Box::new(BufferedReader::new(buf_reader)), + Some(ctrlc), + redirect_stdin.span, + ), redirect_stdin.span, None, )