diff --git a/crates/nu-command/src/filters/each.rs b/crates/nu-command/src/filters/each.rs index 7200be565e..d627b2b018 100644 --- a/crates/nu-command/src/filters/each.rs +++ b/crates/nu-command/src/filters/each.rs @@ -164,6 +164,7 @@ with 'transpose' first."# redirect_stderr, ) { Ok(v) => Some(v.into_value(span)), + Err(ShellError::Continue(v)) => Some(Value::nothing(v)), Err(ShellError::Break(_)) => None, Err(error) => { let error = chain_error_with_input(error, input_span); @@ -188,6 +189,7 @@ with 'transpose' first."# let x = match x { Ok(x) => x, + Err(ShellError::Continue(v)) => return Some(Value::nothing(v)), Err(ShellError::Break(_)) => return None, Err(err) => { return Some(Value::Error { @@ -212,6 +214,7 @@ with 'transpose' first."# redirect_stderr, ) { Ok(v) => Some(v.into_value(span)), + Err(ShellError::Continue(v)) => Some(Value::nothing(v)), Err(ShellError::Break(_)) => None, Err(error) => { let error = Box::new(chain_error_with_input(error, input_span)); diff --git a/crates/nu-command/tests/commands/each.rs b/crates/nu-command/tests/commands/each.rs index 0681d9e639..750e108648 100644 --- a/crates/nu-command/tests/commands/each.rs +++ b/crates/nu-command/tests/commands/each.rs @@ -73,3 +73,19 @@ fn each_while_uses_enumerate_index() { assert_eq!(actual.out, "[0, 1, 2, 3]"); } + +#[test] +fn each_element_continue_command() { + let actual = + nu!("[1,2,3,4,6,7] | each { |x| if ($x mod 2 == 0) {continue} else { $x }} | to nuon"); + + assert_eq!(actual.out, "[1, 3, 7]"); +} + +#[test] +fn each_element_break_command() { + let actual = + nu!("[1,2,5,4,6,7] | each { |x| if ($x mod 3 == 0) {break} else { $x }} | to nuon"); + + assert_eq!(actual.out, "[1, 2, 5, 4]"); +}