WIP fix for the error bubbling (#1597)

This commit is contained in:
Jonathan Turner 2020-04-16 16:25:24 +12:00 committed by GitHub
parent 928188b18e
commit ee778d2b03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 3 deletions

View File

@ -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;
}

View File

@ -45,6 +45,7 @@ impl PerItemCommand for Each {
tag
} => {
let mut context = Context::from_raw(&raw_args, &registry);
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<Value> = 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));

View File

@ -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<Value> = 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));

View File

@ -147,6 +147,10 @@ impl Context {
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 {
let errors = self.current_errors.clone();
let mut errors = errors.lock();