From 9870c7c9a63d8fecbf42173a7c25ee43bb87fcc2 Mon Sep 17 00:00:00 2001 From: PhotonBursted Date: Tue, 22 Oct 2024 18:30:48 +0200 Subject: [PATCH] Defensive handling of errors when transposing (#14096) # Description This PR aims to close #14027, in which it was noticed that the transpose command "swallows" error messages. *Note that in exploring the linked issue, [other situations were identified](https://github.com/nushell/nushell/issues/14027#issuecomment-2414602880) which also produce inconsistent behaviour. These have knowingly been omitted from this PR, to minimize its scope, and since they seem to have a different cause. It's probably best to make a separate issue/PR in which to tackle a broader scan of error handling, with a suspected relation to streams.* # User-Facing Changes The user will see errors from deeper in the pipeline, in case the errors originated there. # Tests + Formatting Toolkit PR check was run successfully. One test was added, covering this exact situation, in order to prevent regressions. The bug is relatively obscure, so it may be prone to reappear during refactorings. --- crates/nu-command/src/filters/transpose.rs | 6 ++++++ crates/nu-command/tests/commands/transpose.rs | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/crates/nu-command/src/filters/transpose.rs b/crates/nu-command/src/filters/transpose.rs index 813a4733b2..873a21c90d 100644 --- a/crates/nu-command/src/filters/transpose.rs +++ b/crates/nu-command/src/filters/transpose.rs @@ -175,6 +175,12 @@ pub fn transpose( let metadata = input.metadata(); let input: Vec<_> = input.into_iter().collect(); + // Ensure error values are propagated + for i in input.iter() { + if let Value::Error { .. } = i { + return Ok(i.clone().into_pipeline_data_with_metadata(metadata)); + } + } let descs = get_columns(&input); diff --git a/crates/nu-command/tests/commands/transpose.rs b/crates/nu-command/tests/commands/transpose.rs index a155319bfc..29a7632af3 100644 --- a/crates/nu-command/tests/commands/transpose.rs +++ b/crates/nu-command/tests/commands/transpose.rs @@ -20,3 +20,15 @@ fn row_but_all() { assert!(actual.out.contains("foo: [1, 2]")); } + +#[test] +fn throw_inner_error() { + let error_msg = "This message should show up"; + let error = format!("(error make {{ msg: \"{}\" }})", error_msg); + let actual = nu!(format!( + "[[key value]; [foo 1] [foo 2] [{} 3]] | transpose", + error + )); + + assert!(actual.err.contains(error.as_str())); +}