mirror of
https://github.com/nushell/nushell.git
synced 2025-08-13 18:17:29 +02:00
Fix try
not working with let
, etc. (#13885)
# Description Partialy addresses #13868. `try` does not catch non-zero exit code errors from the last command in a pipeline if the result is assigned to a variable using `let` (or `mut`). This was fixed by adding a new `OutDest::Value` case. This is used when the pipeline is in a "value" position. I.e., it will be collected into a value. This ended up replacing most of the usages of `OutDest::Capture`. So, this PR also renames `OutDest::Capture` to `OutDest::PipeSeparate` to better fit the few remaining use cases for it. # User-Facing Changes Bug fix. # Tests + Formatting Added two tests.
This commit is contained in:
@ -235,7 +235,7 @@ pub fn eval_expression<D: DebugContext>(
|
||||
stack: &mut Stack,
|
||||
expr: &Expression,
|
||||
) -> Result<Value, ShellError> {
|
||||
let stack = &mut stack.start_capture();
|
||||
let stack = &mut stack.start_collect_value();
|
||||
<EvalRuntime as Eval>::eval::<D>(engine_state, stack, expr)
|
||||
}
|
||||
|
||||
@ -278,7 +278,7 @@ pub fn eval_expression_with_input<D: DebugContext>(
|
||||
let block = engine_state.get_block(*block_id);
|
||||
|
||||
if !full_cell_path.tail.is_empty() {
|
||||
let stack = &mut stack.start_capture();
|
||||
let stack = &mut stack.start_collect_value();
|
||||
// FIXME: protect this collect with ctrl-c
|
||||
input = eval_subexpression::<D>(engine_state, stack, block, input)?
|
||||
.into_value(*span)?
|
||||
@ -325,7 +325,7 @@ fn eval_redirection<D: DebugContext>(
|
||||
}
|
||||
RedirectionTarget::Pipe { .. } => {
|
||||
let dest = match next_out {
|
||||
None | Some(OutDest::Capture) => OutDest::Pipe,
|
||||
None | Some(OutDest::PipeSeparate) => OutDest::Pipe,
|
||||
Some(next) => next,
|
||||
};
|
||||
Ok(Redirection::Pipe(dest))
|
||||
@ -357,7 +357,7 @@ fn eval_element_redirection<D: DebugContext>(
|
||||
let stderr = eval_redirection::<D>(engine_state, stack, target, None)?;
|
||||
if matches!(stderr, Redirection::Pipe(OutDest::Pipe)) {
|
||||
let dest = match next_out {
|
||||
None | Some(OutDest::Capture) => OutDest::Pipe,
|
||||
None | Some(OutDest::PipeSeparate) => OutDest::Pipe,
|
||||
Some(next) => next,
|
||||
};
|
||||
// e>| redirection, don't override current stack `stdout`
|
||||
|
Reference in New Issue
Block a user