ensure exit codes in more cases (#4803)

This commit is contained in:
JT 2022-03-10 06:29:23 -05:00 committed by GitHub
parent 12bf23faa6
commit 9abb14b5fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 14 deletions

View file

@ -19,13 +19,22 @@ pub fn print_pipeline_data(
let stdout = std::io::stdout();
if let PipelineData::ExternalStream {
stdout: Some(stream),
stdout: stream,
exit_code,
..
} = input
{
for s in stream {
let _ = stdout.lock().write_all(s?.as_binary()?);
if let Some(stream) = stream {
for s in stream {
let _ = stdout.lock().write_all(s?.as_binary()?);
}
}
// Make sure everything has finished
if let Some(exit_code) = exit_code {
let _: Vec<_> = exit_code.into_iter().collect();
}
return Ok(());
}

View file

@ -87,9 +87,14 @@ pub(crate) fn evaluate(
pub fn print_table_or_error(
engine_state: &EngineState,
stack: &mut Stack,
pipeline_data: PipelineData,
mut pipeline_data: PipelineData,
config: &Config,
) {
let exit_code = match &mut pipeline_data {
PipelineData::ExternalStream { exit_code, .. } => exit_code.take(),
_ => None,
};
match engine_state.find_decl("table".as_bytes()) {
Some(decl_id) => {
let table = engine_state.get_decl(decl_id).run(
@ -100,12 +105,7 @@ pub fn print_table_or_error(
);
match table {
Ok(mut table) => {
let exit_code = match &mut table {
PipelineData::ExternalStream { exit_code, .. } => exit_code.take(),
_ => None,
};
Ok(table) => {
for item in table {
let stdout = std::io::stdout();
@ -125,10 +125,6 @@ pub fn print_table_or_error(
Err(err) => eprintln!("{}", err),
};
}
if let Some(exit_code) = exit_code {
let _: Vec<_> = exit_code.into_iter().collect();
}
}
Err(error) => {
let working_set = StateWorkingSet::new(engine_state);
@ -161,4 +157,9 @@ pub fn print_table_or_error(
}
}
};
// Make sure everything has finished
if let Some(exit_code) = exit_code {
let _: Vec<_> = exit_code.into_iter().collect();
}
}