mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 05:04:40 +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:
@ -270,7 +270,7 @@ impl Command for Save {
|
||||
}
|
||||
|
||||
fn pipe_redirection(&self) -> (Option<OutDest>, Option<OutDest>) {
|
||||
(Some(OutDest::Capture), Some(OutDest::Capture))
|
||||
(Some(OutDest::PipeSeparate), Some(OutDest::PipeSeparate))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ use it in your pipeline."#
|
||||
let tee_thread = spawn_tee(info.clone(), eval_block)?;
|
||||
let tee = IoTee::new(stderr, tee_thread);
|
||||
match stack.stderr() {
|
||||
OutDest::Pipe | OutDest::Capture => {
|
||||
OutDest::Pipe | OutDest::PipeSeparate | OutDest::Value => {
|
||||
child.stderr = Some(ChildPipe::Tee(Box::new(tee)));
|
||||
Ok(None)
|
||||
}
|
||||
@ -176,7 +176,7 @@ use it in your pipeline."#
|
||||
|
||||
if let Some(stdout) = child.stdout.take() {
|
||||
match stack.stdout() {
|
||||
OutDest::Pipe | OutDest::Capture => {
|
||||
OutDest::Pipe | OutDest::PipeSeparate | OutDest::Value => {
|
||||
child.stdout = Some(stdout);
|
||||
Ok(())
|
||||
}
|
||||
@ -191,7 +191,7 @@ use it in your pipeline."#
|
||||
let stderr_thread = if let Some(stderr) = child.stderr.take() {
|
||||
let info = info.clone();
|
||||
match stack.stderr() {
|
||||
OutDest::Pipe | OutDest::Capture => {
|
||||
OutDest::Pipe | OutDest::PipeSeparate | OutDest::Value => {
|
||||
child.stderr = Some(stderr);
|
||||
Ok(None)
|
||||
}
|
||||
@ -213,7 +213,7 @@ use it in your pipeline."#
|
||||
let tee_thread = spawn_tee(info.clone(), eval_block)?;
|
||||
let tee = IoTee::new(stdout, tee_thread);
|
||||
match stack.stdout() {
|
||||
OutDest::Pipe | OutDest::Capture => {
|
||||
OutDest::Pipe | OutDest::PipeSeparate | OutDest::Value => {
|
||||
child.stdout = Some(ChildPipe::Tee(Box::new(tee)));
|
||||
Ok(())
|
||||
}
|
||||
@ -280,7 +280,7 @@ use it in your pipeline."#
|
||||
}
|
||||
|
||||
fn pipe_redirection(&self) -> (Option<OutDest>, Option<OutDest>) {
|
||||
(Some(OutDest::Capture), Some(OutDest::Capture))
|
||||
(Some(OutDest::PipeSeparate), Some(OutDest::PipeSeparate))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,6 +93,6 @@ impl Command for Complete {
|
||||
}
|
||||
|
||||
fn pipe_redirection(&self) -> (Option<OutDest>, Option<OutDest>) {
|
||||
(Some(OutDest::Capture), Some(OutDest::Capture))
|
||||
(Some(OutDest::PipeSeparate), Some(OutDest::PipeSeparate))
|
||||
}
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ fn write_pipeline_data(
|
||||
} else if let PipelineData::Value(Value::Binary { val, .. }, ..) = data {
|
||||
writer.write_all(&val)?;
|
||||
} else {
|
||||
stack.start_capture();
|
||||
stack.start_collect_value();
|
||||
|
||||
// Turn off color as we pass data through
|
||||
Arc::make_mut(&mut engine_state.config).use_ansi_coloring = false;
|
||||
@ -367,7 +367,7 @@ pub fn command_not_found(
|
||||
) -> ShellError {
|
||||
// Run the `command_not_found` hook if there is one.
|
||||
if let Some(hook) = &stack.get_config(engine_state).hooks.command_not_found {
|
||||
let mut stack = stack.start_capture();
|
||||
let mut stack = stack.start_collect_value();
|
||||
// Set a special environment variable to avoid infinite loops when the
|
||||
// `command_not_found` hook triggers itself.
|
||||
let canary = "ENTERED_COMMAND_NOT_FOUND";
|
||||
|
Reference in New Issue
Block a user