Bubble errors even if pipeline isn't used (#2080)

This commit is contained in:
Jonathan Turner 2020-06-30 05:39:11 +12:00 committed by GitHub
parent bcddeb3c1f
commit ed10aafa6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 64 additions and 37 deletions

View File

@ -121,7 +121,7 @@ pub async fn autoview(context: RunnableContext) -> Result<OutputStream, ShellErr
if let Some(table) = table {
let command_args = create_default_command_args(&context).with_input(stream);
let result = table.run(command_args, &context.registry).await;
let result = table.run(command_args, &context.registry).await?;
result.collect::<Vec<_>>().await;
}
}
@ -138,7 +138,7 @@ pub async fn autoview(context: RunnableContext) -> Result<OutputStream, ShellErr
);
let command_args =
create_default_command_args(&context).with_input(stream);
let result = text.run(command_args, &context.registry).await;
let result = text.run(command_args, &context.registry).await?;
result.collect::<Vec<_>>().await;
} else {
out!("{}", s);
@ -161,7 +161,7 @@ pub async fn autoview(context: RunnableContext) -> Result<OutputStream, ShellErr
);
let command_args =
create_default_command_args(&context).with_input(stream);
let result = text.run(command_args, &context.registry).await;
let result = text.run(command_args, &context.registry).await?;
result.collect::<Vec<_>>().await;
} else {
out!("{}\n", s);
@ -236,7 +236,7 @@ pub async fn autoview(context: RunnableContext) -> Result<OutputStream, ShellErr
stream.push_back(x);
let command_args =
create_default_command_args(&context).with_input(stream);
let result = binary.run(command_args, &context.registry).await;
let result = binary.run(command_args, &context.registry).await?;
result.collect::<Vec<_>>().await;
} else {
use pretty_hex::*;
@ -298,7 +298,7 @@ pub async fn autoview(context: RunnableContext) -> Result<OutputStream, ShellErr
stream.push_back(x);
let command_args =
create_default_command_args(&context).with_input(stream);
let result = table.run(command_args, &context.registry).await;
let result = table.run(command_args, &context.registry).await?;
result.collect::<Vec<_>>().await;
} else {
out!("{:?}", item);

View File

@ -37,7 +37,7 @@ pub(crate) async fn run_internal_command(
&scope,
objects,
)
.await
.await?
};
let head = Arc::new(command.args.head.clone());
@ -89,37 +89,49 @@ pub(crate) async fn run_internal_command(
scope: (&*scope).clone(),
},
};
let mut result = converter
let result = converter
.run(
new_args.with_input(vec![tagged_contents]),
&context.registry,
)
.await;
let result_vec: Vec<Result<ReturnSuccess, ShellError>> =
result.drain_vec().await;
let mut output = vec![];
for res in result_vec {
match res {
Ok(ReturnSuccess::Value(Value {
value: UntaggedValue::Table(list),
..
})) => {
for l in list {
output.push(Ok(l));
match result {
Ok(mut result) => {
let result_vec: Vec<Result<ReturnSuccess, ShellError>> =
result.drain_vec().await;
let mut output = vec![];
for res in result_vec {
match res {
Ok(ReturnSuccess::Value(Value {
value: UntaggedValue::Table(list),
..
})) => {
for l in list {
output.push(Ok(l));
}
}
Ok(ReturnSuccess::Value(Value {
value,
..
})) => {
output
.push(Ok(value
.into_value(contents_tag.clone())));
}
Err(e) => output.push(Err(e)),
_ => {}
}
}
Ok(ReturnSuccess::Value(Value { value, .. })) => {
output.push(Ok(
value.into_value(contents_tag.clone())
));
}
Err(e) => output.push(Err(e)),
_ => {}
futures::stream::iter(output).to_input_stream()
}
Err(e) => {
context.add_error(e);
InputStream::empty()
}
}
futures::stream::iter(output).to_input_stream()
} else {
InputStream::one(tagged_contents)
}

View File

@ -343,18 +343,19 @@ impl Command {
self.0.usage()
}
pub async fn run(&self, args: CommandArgs, registry: &CommandRegistry) -> OutputStream {
pub async fn run(
&self,
args: CommandArgs,
registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> {
if args.call_info.switch_present("help") {
let cl = self.0.clone();
let registry = registry.clone();
OutputStream::one(Ok(ReturnSuccess::Value(
Ok(OutputStream::one(Ok(ReturnSuccess::Value(
UntaggedValue::string(get_help(&*cl, &registry)).into_value(Tag::unknown()),
)))
))))
} else {
match self.0.run(args, registry).await {
Ok(stream) => stream,
Err(err) => OutputStream::one(Err(err)),
}
self.0.run(args, registry).await
}
}

View File

@ -158,7 +158,7 @@ async fn enter(
};
let mut result = converter
.run(new_args.with_input(vec![tagged_contents]), &registry)
.await;
.await?;
let result_vec: Vec<Result<ReturnSuccess, ShellError>> =
result.drain_vec().await;

View File

@ -232,7 +232,7 @@ async fn save(
scope,
},
};
let mut result = converter.run(new_args.with_input(input), &registry).await;
let mut result = converter.run(new_args.with_input(input), &registry).await?;
let result_vec: Vec<Result<ReturnSuccess, ShellError>> =
result.drain_vec().await;
if converter.is_binary() {

View File

@ -184,6 +184,10 @@ impl Context {
self.current_errors.lock().clone()
}
pub(crate) fn add_error(&self, err: ShellError) {
self.current_errors.lock().push(err);
}
pub(crate) fn maybe_print_errors(&mut self, source: Text) -> bool {
let errors = self.current_errors.clone();
let mut errors = errors.lock();
@ -232,7 +236,7 @@ impl Context {
args: hir::Call,
scope: &Scope,
input: InputStream,
) -> OutputStream {
) -> Result<OutputStream, ShellError> {
let command_args = self.command_args(args, input, name_tag, scope);
command.run(command_args, self.registry()).await
}

View File

@ -10,6 +10,16 @@ fn shows_error_for_command_not_found() {
assert!(actual.err.contains("Command not found"));
}
#[test]
fn shows_error_for_command_not_found_in_pipeline() {
let actual = nu!(
cwd: ".",
"ferris_is_not_here.exe | echo done"
);
assert!(actual.err.contains("Command not found"));
}
#[test]
fn automatically_change_directory() {
use nu_test_support::playground::Playground;