From 0504a7a77677e70feac752a76c1cf48d55c84e2a Mon Sep 17 00:00:00 2001 From: JT Date: Tue, 12 Oct 2021 06:35:40 +1300 Subject: [PATCH 1/2] Make errors emit first --- TODO.md | 2 +- crates/nu-command/src/viewers/table.rs | 19 ++++++++++++------- src/main.rs | 9 ++++++++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/TODO.md b/TODO.md index 13df448caa..8d55d0cb5c 100644 --- a/TODO.md +++ b/TODO.md @@ -25,11 +25,11 @@ - [x] Modules and imports - [x] Exports - [x] Source +- [x] Error shortcircuit (stopping on first error). Revised: errors emit first, but can be seen by commands. - [ ] Input/output types - [ ] Support for `$in` - [ ] Value serialization - [ ] Handling rows with missing columns during a cell path -- [ ] Error shortcircuit (stopping on first error) - [ ] ctrl-c support - [ ] operator overflow - [ ] finish operator type-checking diff --git a/crates/nu-command/src/viewers/table.rs b/crates/nu-command/src/viewers/table.rs index b1d31ba299..f0527599f6 100644 --- a/crates/nu-command/src/viewers/table.rs +++ b/crates/nu-command/src/viewers/table.rs @@ -1,6 +1,6 @@ use nu_protocol::ast::{Call, PathMember}; use nu_protocol::engine::{Command, EvaluationContext}; -use nu_protocol::{Signature, Span, Value}; +use nu_protocol::{ShellError, Signature, Span, Value}; use nu_table::StyledString; use std::collections::HashMap; use terminal_size::{Height, Width}; @@ -35,7 +35,7 @@ impl Command for Table { match input { Value::List { vals, .. } => { - let table = convert_to_table(vals); + let table = convert_to_table(vals)?; if let Some(table) = table { let result = nu_table::draw_table(&table, term_width, &HashMap::new()); @@ -49,7 +49,7 @@ impl Command for Table { } } Value::Stream { stream, .. } => { - let table = convert_to_table(stream); + let table = convert_to_table(stream)?; if let Some(table) = table { let result = nu_table::draw_table(&table, term_width, &HashMap::new()); @@ -96,7 +96,9 @@ impl Command for Table { } } -fn convert_to_table(iter: impl IntoIterator) -> Option { +fn convert_to_table( + iter: impl IntoIterator, +) -> Result, ShellError> { let mut iter = iter.into_iter().peekable(); if let Some(first) = iter.peek() { @@ -109,6 +111,9 @@ fn convert_to_table(iter: impl IntoIterator) -> Option) -> Option) -> Option Result<()> { }; match eval_block(&state, &block, Value::nothing()) { - Ok(value) => print_value(value, &state)?, + Ok(value) => { + if let Err(err) = print_value(value, &state) { + let engine_state = engine_state.borrow(); + let working_set = StateWorkingSet::new(&*engine_state); + + report_error(&working_set, &err); + } + } Err(err) => { let engine_state = engine_state.borrow(); let working_set = StateWorkingSet::new(&*engine_state); From ba73e0eb06b0d2ab9d2e12ce0aaef8eda7d03674 Mon Sep 17 00:00:00 2001 From: JT Date: Tue, 12 Oct 2021 06:37:22 +1300 Subject: [PATCH 2/2] Another early emit --- crates/nu-command/src/viewers/table.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/nu-command/src/viewers/table.rs b/crates/nu-command/src/viewers/table.rs index f0527599f6..93338f3589 100644 --- a/crates/nu-command/src/viewers/table.rs +++ b/crates/nu-command/src/viewers/table.rs @@ -91,6 +91,7 @@ impl Command for Table { span: call.head, }) } + Value::Error { error } => Err(error), x => Ok(x), } }