forked from extern/nushell
WIP fix for the error bubbling (#1597)
This commit is contained in:
parent
928188b18e
commit
ee778d2b03
@ -152,7 +152,8 @@ pub(crate) fn run_internal_command(
|
|||||||
value: UntaggedValue::Error(err),
|
value: UntaggedValue::Error(err),
|
||||||
..
|
..
|
||||||
})) => {
|
})) => {
|
||||||
context.error(err);
|
context.error(err.clone());
|
||||||
|
yield Err(err);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ impl PerItemCommand for Each {
|
|||||||
tag
|
tag
|
||||||
} => {
|
} => {
|
||||||
let mut context = Context::from_raw(&raw_args, ®istry);
|
let mut context = Context::from_raw(&raw_args, ®istry);
|
||||||
|
let input_clone = input.clone();
|
||||||
let input_stream = async_stream! {
|
let input_stream = async_stream! {
|
||||||
yield Ok(input.clone())
|
yield Ok(input.clone())
|
||||||
}.to_input_stream();
|
}.to_input_stream();
|
||||||
@ -53,12 +54,17 @@ impl PerItemCommand for Each {
|
|||||||
ClassifiedPipeline::new(block.clone(), None),
|
ClassifiedPipeline::new(block.clone(), None),
|
||||||
&mut context,
|
&mut context,
|
||||||
Some(input_stream),
|
Some(input_stream),
|
||||||
&Scope::empty(),
|
&Scope::new(input_clone),
|
||||||
).await;
|
).await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(Some(v)) => {
|
Ok(Some(v)) => {
|
||||||
let results: Vec<Value> = v.collect().await;
|
let results: Vec<Value> = v.collect().await;
|
||||||
|
let errors = context.get_errors();
|
||||||
|
if let Some(error) = errors.first() {
|
||||||
|
yield Err(error.clone());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for result in results {
|
for result in results {
|
||||||
yield Ok(ReturnSuccess::Value(result));
|
yield Ok(ReturnSuccess::Value(result));
|
||||||
|
@ -47,7 +47,7 @@ impl PerItemCommand for AliasCommand {
|
|||||||
let raw_args = raw_args.clone();
|
let raw_args = raw_args.clone();
|
||||||
let block = self.block.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 {
|
if let Some(positional) = &call_info.args.positional {
|
||||||
for (pos, arg) in positional.iter().enumerate() {
|
for (pos, arg) in positional.iter().enumerate() {
|
||||||
scope = scope.set_var(self.args[pos].to_string(), arg.clone());
|
scope = scope.set_var(self.args[pos].to_string(), arg.clone());
|
||||||
@ -70,6 +70,11 @@ impl PerItemCommand for AliasCommand {
|
|||||||
match result {
|
match result {
|
||||||
Ok(Some(v)) => {
|
Ok(Some(v)) => {
|
||||||
let results: Vec<Value> = v.collect().await;
|
let results: Vec<Value> = v.collect().await;
|
||||||
|
let errors = context.get_errors();
|
||||||
|
if let Some(error) = errors.first() {
|
||||||
|
yield Err(error.clone());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for result in results {
|
for result in results {
|
||||||
yield Ok(ReturnSuccess::Value(result));
|
yield Ok(ReturnSuccess::Value(result));
|
||||||
|
@ -147,6 +147,10 @@ impl Context {
|
|||||||
self.with_errors(|errors| errors.push(error))
|
self.with_errors(|errors| errors.push(error))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn get_errors(&self) -> Vec<ShellError> {
|
||||||
|
self.current_errors.lock().clone()
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn maybe_print_errors(&mut self, source: Text) -> bool {
|
pub(crate) fn maybe_print_errors(&mut self, source: Text) -> bool {
|
||||||
let errors = self.current_errors.clone();
|
let errors = self.current_errors.clone();
|
||||||
let mut errors = errors.lock();
|
let mut errors = errors.lock();
|
||||||
|
Loading…
Reference in New Issue
Block a user