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..93338f3589 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()); @@ -91,12 +91,15 @@ impl Command for Table { span: call.head, }) } + Value::Error { error } => Err(error), x => Ok(x), } } } -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 +112,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);