diff --git a/crates/nu-command/src/filters/all.rs b/crates/nu-command/src/filters/all.rs index ed81f74506..f34668cd85 100644 --- a/crates/nu-command/src/filters/all.rs +++ b/crates/nu-command/src/filters/all.rs @@ -66,27 +66,31 @@ impl Command for All { let ctrlc = engine_state.ctrlc.clone(); let engine_state = engine_state.clone(); - Ok(Value::Bool { - val: input.into_interruptible_iter(ctrlc).all(move |value| { - if let Some(var_id) = var_id { - stack.add_var(var_id, value); - } + for value in input.into_interruptible_iter(ctrlc) { + if let Some(var_id) = var_id { + stack.add_var(var_id, value); + } - eval_block( - &engine_state, - &mut stack, - block, - PipelineData::new(span), - call.redirect_stdout, - call.redirect_stderr, - ) - .map_or(false, |pipeline_data| { - pipeline_data.into_value(span).is_true() - }) - }), - span, + let eval = eval_block( + &engine_state, + &mut stack, + block, + PipelineData::new(span), + call.redirect_stdout, + call.redirect_stderr, + ); + match eval { + Err(e) => { + return Err(e); + } + Ok(pipeline_data) => { + if !pipeline_data.into_value(span).is_true() { + return Ok(Value::Bool { val: false, span }.into_pipeline_data()); + } + } + } } - .into_pipeline_data()) + Ok(Value::Bool { val: true, span }.into_pipeline_data()) } } diff --git a/crates/nu-command/src/filters/any.rs b/crates/nu-command/src/filters/any.rs index bf30b59629..2be85de11a 100644 --- a/crates/nu-command/src/filters/any.rs +++ b/crates/nu-command/src/filters/any.rs @@ -65,27 +65,31 @@ impl Command for Any { let ctrlc = engine_state.ctrlc.clone(); let engine_state = engine_state.clone(); - Ok(Value::Bool { - val: input.into_interruptible_iter(ctrlc).any(move |value| { - if let Some(var_id) = var_id { - stack.add_var(var_id, value); - } + for value in input.into_interruptible_iter(ctrlc) { + if let Some(var_id) = var_id { + stack.add_var(var_id, value); + } - eval_block( - &engine_state, - &mut stack, - block, - PipelineData::new(span), - call.redirect_stdout, - call.redirect_stderr, - ) - .map_or(false, |pipeline_data| { - pipeline_data.into_value(span).is_true() - }) - }), - span, + let eval = eval_block( + &engine_state, + &mut stack, + block, + PipelineData::new(span), + call.redirect_stdout, + call.redirect_stderr, + ); + match eval { + Err(e) => { + return Err(e); + } + Ok(pipeline_data) => { + if pipeline_data.into_value(span).is_true() { + return Ok(Value::Bool { val: true, span }.into_pipeline_data()); + } + } + } } - .into_pipeline_data()) + Ok(Value::Bool { val: false, span }.into_pipeline_data()) } } diff --git a/crates/nu-command/tests/commands/all.rs b/crates/nu-command/tests/commands/all.rs index ea6dc3f8bb..3882da785a 100644 --- a/crates/nu-command/tests/commands/all.rs +++ b/crates/nu-command/tests/commands/all.rs @@ -55,3 +55,15 @@ fn checks_all_columns_of_a_table_is_true() { assert_eq!(actual.out, "true"); } + +#[test] +fn checks_if_all_returns_error_with_invalid_command() { + let actual = nu!( + cwd: ".", pipeline( + r#" + [red orange yellow green blue purple] | all? ($it | st length) > 4 + "# + )); + + assert!(actual.err.contains("can't run executable") || actual.err.contains("type_mismatch")); +} diff --git a/crates/nu-command/tests/commands/any.rs b/crates/nu-command/tests/commands/any.rs index 8489497455..a3aad7cfa0 100644 --- a/crates/nu-command/tests/commands/any.rs +++ b/crates/nu-command/tests/commands/any.rs @@ -31,3 +31,15 @@ fn checks_any_column_of_a_table_is_true() { assert_eq!(actual.out, "true"); } + +#[test] +fn checks_if_any_returns_error_with_invalid_command() { + let actual = nu!( + cwd: ".", pipeline( + r#" + [red orange yellow green blue purple] | any? ($it | st length) > 4 + "# + )); + + assert!(actual.err.contains("can't run executable") || actual.err.contains("type_mismatch")); +}