diff --git a/crates/nu-cmd-lang/src/core_commands/try_.rs b/crates/nu-cmd-lang/src/core_commands/try_.rs index 0c6e8b174f..14c72276bb 100644 --- a/crates/nu-cmd-lang/src/core_commands/try_.rs +++ b/crates/nu-cmd-lang/src/core_commands/try_.rs @@ -47,6 +47,7 @@ impl Command for Try { call: &Call, input: PipelineData, ) -> Result { + let head = call.head; // This is compiled specially by the IR compiler. The code here is never used when // running in IR mode. let call = call.assert_ast_call()?; @@ -61,16 +62,14 @@ impl Command for Try { let try_block = engine_state.get_block(try_block); let eval_block = get_eval_block(engine_state); - match eval_block(engine_state, stack, try_block, input) { - Err(err) => run_catch(err, call.head, catch_block, engine_state, stack, eval_block), - Ok(PipelineData::Value(Value::Error { error, .. }, ..)) => run_catch( - *error, - call.head, - catch_block, - engine_state, - stack, - eval_block, - ), + let result = eval_block(engine_state, stack, try_block, input) + .and_then(|pipeline| pipeline.write_to_out_dests(engine_state, stack)); + + match result { + Err(err) => run_catch(err, head, catch_block, engine_state, stack, eval_block), + Ok(PipelineData::Value(Value::Error { error, .. }, ..)) => { + run_catch(*error, head, catch_block, engine_state, stack, eval_block) + } Ok(pipeline) => Ok(pipeline), } } diff --git a/crates/nu-protocol/src/pipeline/pipeline_data.rs b/crates/nu-protocol/src/pipeline/pipeline_data.rs index 48638e15ac..40dfff17e3 100644 --- a/crates/nu-protocol/src/pipeline/pipeline_data.rs +++ b/crates/nu-protocol/src/pipeline/pipeline_data.rs @@ -145,10 +145,10 @@ impl PipelineData { stack: &mut Stack, ) -> Result { match (self, stack.stdout()) { + (data, OutDest::Pipe | OutDest::Capture) => return Ok(data), (PipelineData::ByteStream(stream, ..), stdout) => { stream.write_to_out_dests(stdout, stack.stderr())?; } - (data, OutDest::Pipe | OutDest::Capture) => return Ok(data), (PipelineData::Empty, ..) => {} (PipelineData::Value(..), OutDest::Null) => {} (PipelineData::ListStream(stream, ..), OutDest::Null) => {