mirror of
https://github.com/nushell/nushell.git
synced 2025-03-28 00:32:17 +01:00
Respect non-zero exit code in subexpressions and blocks (#8984)
# Description This PR changes the way we handled non-zero exit codes to be and early exit between `foo; bar`. If `foo` in the example has a non-zero exit code, `bar` wouldn't be run. This also affects subexpressions.
This commit is contained in:
parent
f8dc3421b0
commit
2ffe30ecf0
@ -723,7 +723,13 @@ pub fn eval_block(
|
|||||||
let mut v: Vec<_> = exit_code.collect();
|
let mut v: Vec<_> = exit_code.collect();
|
||||||
|
|
||||||
if let Some(v) = v.pop() {
|
if let Some(v) = v.pop() {
|
||||||
|
let break_loop = !matches!(v.as_i64(), Ok(0));
|
||||||
|
|
||||||
stack.add_env_var("LAST_EXIT_CODE".into(), v);
|
stack.add_env_var("LAST_EXIT_CODE".into(), v);
|
||||||
|
if break_loop {
|
||||||
|
input = PipelineData::empty();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -741,31 +747,9 @@ pub fn eval_subexpression(
|
|||||||
engine_state: &EngineState,
|
engine_state: &EngineState,
|
||||||
stack: &mut Stack,
|
stack: &mut Stack,
|
||||||
block: &Block,
|
block: &Block,
|
||||||
mut input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
for pipeline in block.pipelines.iter() {
|
eval_block(engine_state, stack, block, input, true, false)
|
||||||
let mut stderr_writer_jobs = vec![];
|
|
||||||
for expr in pipeline.elements.iter() {
|
|
||||||
input = eval_element_with_input(
|
|
||||||
engine_state,
|
|
||||||
stack,
|
|
||||||
expr,
|
|
||||||
input,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
&mut stderr_writer_jobs,
|
|
||||||
)?
|
|
||||||
.0
|
|
||||||
}
|
|
||||||
// `eval_element_with_input` may creates some threads
|
|
||||||
// to write stderr message to a file, here we need to wait and make sure that it's
|
|
||||||
// finished.
|
|
||||||
for h in stderr_writer_jobs {
|
|
||||||
let _ = h.join();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(input)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn eval_variable(
|
pub fn eval_variable(
|
||||||
|
Loading…
Reference in New Issue
Block a user