diff --git a/crates/nu-cli/src/commands/classified/internal.rs b/crates/nu-cli/src/commands/classified/internal.rs index 2a76e0f406..2480def60a 100644 --- a/crates/nu-cli/src/commands/classified/internal.rs +++ b/crates/nu-cli/src/commands/classified/internal.rs @@ -152,7 +152,8 @@ pub(crate) fn run_internal_command( value: UntaggedValue::Error(err), .. })) => { - context.error(err); + context.error(err.clone()); + yield Err(err); break; } diff --git a/crates/nu-cli/src/commands/each.rs b/crates/nu-cli/src/commands/each.rs index 61d2b2de04..db9949f7ae 100644 --- a/crates/nu-cli/src/commands/each.rs +++ b/crates/nu-cli/src/commands/each.rs @@ -45,6 +45,7 @@ impl PerItemCommand for Each { tag } => { let mut context = Context::from_raw(&raw_args, ®istry); + let input_clone = input.clone(); let input_stream = async_stream! { yield Ok(input.clone()) }.to_input_stream(); @@ -53,12 +54,17 @@ impl PerItemCommand for Each { ClassifiedPipeline::new(block.clone(), None), &mut context, Some(input_stream), - &Scope::empty(), + &Scope::new(input_clone), ).await; match result { Ok(Some(v)) => { let results: Vec = v.collect().await; + let errors = context.get_errors(); + if let Some(error) = errors.first() { + yield Err(error.clone()); + return; + } for result in results { yield Ok(ReturnSuccess::Value(result)); diff --git a/crates/nu-cli/src/commands/run_alias.rs b/crates/nu-cli/src/commands/run_alias.rs index 14be5d635e..d3725cb9bd 100644 --- a/crates/nu-cli/src/commands/run_alias.rs +++ b/crates/nu-cli/src/commands/run_alias.rs @@ -47,7 +47,7 @@ impl PerItemCommand for AliasCommand { let raw_args = raw_args.clone(); let block = self.block.clone(); - let mut scope = Scope::empty(); + let mut scope = Scope::it_value(input.clone()); if let Some(positional) = &call_info.args.positional { for (pos, arg) in positional.iter().enumerate() { scope = scope.set_var(self.args[pos].to_string(), arg.clone()); @@ -70,6 +70,11 @@ impl PerItemCommand for AliasCommand { match result { Ok(Some(v)) => { let results: Vec = v.collect().await; + let errors = context.get_errors(); + if let Some(error) = errors.first() { + yield Err(error.clone()); + return; + } for result in results { yield Ok(ReturnSuccess::Value(result)); diff --git a/crates/nu-cli/src/context.rs b/crates/nu-cli/src/context.rs index ffae364eeb..d1d97f03cb 100644 --- a/crates/nu-cli/src/context.rs +++ b/crates/nu-cli/src/context.rs @@ -147,6 +147,10 @@ impl Context { self.with_errors(|errors| errors.push(error)) } + pub(crate) fn get_errors(&self) -> Vec { + self.current_errors.lock().clone() + } + pub(crate) fn maybe_print_errors(&mut self, source: Text) -> bool { let errors = self.current_errors.clone(); let mut errors = errors.lock();