From 0aafc29fb5caf437c0e22f22ac1876f2e8857de5 Mon Sep 17 00:00:00 2001 From: Bahex Date: Wed, 27 Nov 2024 15:37:21 +0300 Subject: [PATCH] Propagate existing errors in insert and merge (#14453) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description Propagate existing errors in the pipeline, rather than a type error. # User-Facing Changes Nothing that previously worked should be affected, this should just change the errors. # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` --- crates/nu-command/src/filters/insert.rs | 2 ++ crates/nu-command/src/filters/merge.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/crates/nu-command/src/filters/insert.rs b/crates/nu-command/src/filters/insert.rs index e6f9a7d8d7..0d3a234f58 100644 --- a/crates/nu-command/src/filters/insert.rs +++ b/crates/nu-command/src/filters/insert.rs @@ -129,6 +129,8 @@ fn insert( let replacement: Value = call.req(engine_state, stack, 1)?; match input { + // Propagate errors in the pipeline + PipelineData::Value(Value::Error { error, .. }, ..) => Err(*error), PipelineData::Value(mut value, metadata) => { if let Value::Closure { val, .. } = replacement { match (cell_path.members.first(), &mut value) { diff --git a/crates/nu-command/src/filters/merge.rs b/crates/nu-command/src/filters/merge.rs index e1d3095b20..588138fb42 100644 --- a/crates/nu-command/src/filters/merge.rs +++ b/crates/nu-command/src/filters/merge.rs @@ -120,6 +120,8 @@ repeating this process with row 1, and so on."# PipelineData::Value(Value::Record { val: inp, .. }, ..), Value::Record { val: to_merge, .. }, ) => Ok(Value::record(do_merge(inp, &to_merge), head).into_pipeline_data()), + // Propagate errors in the pipeline + (PipelineData::Value(Value::Error { error, .. }, ..), _) => Err(*error.clone()), (PipelineData::Value(val, ..), ..) => { // Only point the "value originates here" arrow at the merge value // if it was generated from a block. Otherwise, point at the pipeline value. -Leon 2022-10-27