Repository: nushell/nushell (language: rust)

Issue:
`transpose` silently discards list streams
### Describe the bug

When `transpose` is passed a non-table list stream, it returns an empty list.

### How to reproduce

```Nushell
~> generate {|i=1| {out: $i, next: ($i * 2)} } | take 7 | transpose
╭────────────╮
│ empty list │
╰────────────╯
```

### Expected behavior

Throw an error, like `transpose` does for regular lists.

### Configuration

| key                | value                                                        |
| ------------------ | ------------------------------------------------------------ |
| version            | 0.97.1                                                       |
| major              | 0                                                            |
| minor              | 97                                                           |
| patch              | 1                                                            |
| branch             |                                                              |
| commit_hash        |                                                              |
| build_os           | linux-x86_64                                                 |
| build_target       | x86_64-alpine-linux-musl                                     |
| rust_version       | rustc 1.80.1 (3f5fd8dd4 2024-08-06) (Alpine Linux 1.80.1-r0) |
| cargo_version      | cargo 1.80.1 (376290515 2024-07-16)                          |
| build_time         | 2024-08-29 21:40:07 +00:00                                   |
| build_rust_channel | release                                                      |
| allocator          | mimalloc                                                     |
| features           | default, sqlite, system-clipboard, trash                     |
| installed_plugins  | endecode 0.2.0, template 0.1.0                               |


Discussion / hints:
For some reason, adding `collect` doesn't fix it:

```Nushell
~> generate {|i=1| {out: $i, next: ($i * 2)} } | take 7 | collect | transpose
╭────────────╮
│ empty list │
╰────────────╯
```

It seems that `generate` does something, which sticks around even in variables:

```Nushell
~> let list = [1 2 4 8 16 32 64]
~> $list | transpose 
Error: nu::parser::input_type_mismatch

  × Command does not support list<int> input.
   ╭─[entry #32:1:9]
 1 │ $list | transpose 
   ·         ────┬────
   ·             ╰── command doesn't support list<int> input
   ╰────

~> let list = generate {|i=1| {out: $i, next: ($i * 2)} } | take 7
~> $list | transpose 
╭────────────╮
│ empty list │
╰────────────╯
```

Fix patch:
diff --git a/crates/nu-command/src/filters/transpose.rs b/crates/nu-command/src/filters/transpose.rs
index 873a21c90db87..a85e95863edf3 100644
--- a/crates/nu-command/src/filters/transpose.rs
+++ b/crates/nu-command/src/filters/transpose.rs
@@ -175,10 +175,22 @@ 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));
+
+    // Ensure error values are propagated and non-record values are rejected
+    for value in input.iter() {
+        match value {
+            Value::Error { .. } => {
+                return Ok(value.clone().into_pipeline_data_with_metadata(metadata))
+            }
+            Value::Record { .. } => {} // go on, this is what we're looking for
+            _ => {
+                return Err(ShellError::OnlySupportsThisInputType {
+                    exp_input_type: "table or record".into(),
+                    wrong_type: "list<any>".into(),
+                    dst_span: call.head,
+                    src_span: value.span(),
+                })
+            }
         }
     }
 


Test patch:
diff --git a/crates/nu-command/tests/commands/transpose.rs b/crates/nu-command/tests/commands/transpose.rs
index 29a7632af3965..c4448fdaf65c6 100644
--- a/crates/nu-command/tests/commands/transpose.rs
+++ b/crates/nu-command/tests/commands/transpose.rs
@@ -32,3 +32,11 @@ fn throw_inner_error() {
 
     assert!(actual.err.contains(error.as_str()));
 }
+
+#[test]
+fn rejects_non_table_stream_input() {
+    let actual = nu!("[1 2 3] | each { |it| ($it * 2) } | transpose | to nuon");
+
+    assert!(actual.out.is_empty());
+    assert!(actual.err.contains("only table"));
+}