Skip to content

fix: propagate error stream values in length, columns, and is-empty - #18976

Merged
fdncred merged 3 commits into
nushell:mainfrom
sidsri14:fix/length-columns-is-empty-error-values
Sep 10, 2026
Merged

fdncred merged 3 commits into
nushell:mainfrom
sidsri14:fix/length-columns-is-empty-error-values

Conversation

@sidsri14

@sidsri14 sidsri14 commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #18928.

length, columns, and is-empty / is-not-empty silently consumed Value::Error stream items instead of surfacing them, producing wrong silent results. For example, where with a type error could make length report the unfiltered row count, columns return [], or is-empty return the wrong boolean.

This PR makes all three commands propagate the first error encountered in the input stream:

  • length: the ListStream count loop calls unwrap_error() on each value, returning the inner ShellError instead of counting it.
  • columns: scans both Value::List and ListStream inputs for Value::Error before computing columns, returning the inner error.
  • is-empty / is-not-empty: the ListStream and Value branches of empty() return the inner error instead of treating an error item as non-empty.

This is consistent with the error propagation that #16738 established for stream-collecting commands (into_value, unwrap_error); these commands bypassed it with manual iteration.

User-facing changes (Release notes)

length, columns, and is-empty now surface errors from streamed input

Fixed an issue where length, columns, and is-empty / is-not-empty could silently ignore errors in streamed input and return incorrect results instead of surfacing the original error.

For example, [[name size]; [a 100b] [b 200b]] | where size <= 150 | length now errors with nu::shell::operator_incompatible_types instead of returning 2, and likewise for columns / is-empty.

Additional notes

Verification:

  • Added three integration tests, one per affected command, all asserting that the original error is propagated.
  • Confirmed each test reproduces the bug pre-fix: columns returned List([]) instead of erroring, length returned the wrong count, and is-empty returned the wrong boolean.
  • cargo fmt --check -p nu-command: clean
  • cargo clippy -p nu-command --all-targets: clean
  • Full nu-command tests: 2884 pass, 22 fail due to pre-existing Windows symlink/privilege failures such as can not create symlink: A required privilege is not held by the client, unrelated to this change.

AI disclosure: this change was authored with the assistance of an AI coding agent.

The previous tee closure used a positional param that is not bound for stream
inputs, surfacing a 'variable not found' error row that length used to swallow
and count (6 = 5 real rows + 1 masked error). Since length now propagates
stream errors, use the working 'tee { $in | ignore }' closure and assert the
true row count of 5.
@sidsri14
sidsri14 force-pushed the fix/length-columns-is-empty-error-values branch from ce37ef0 to 304e2f1 Compare September 6, 2026 13:25
@sidsri14

sidsri14 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Heads-up on the CI failure from the cargo in root job (Windows): commands::open::sqlite_int_table_operations::case_63_tee (sample.db | get ints | tee {|x| $x | ignore } | flatten | length).

Root cause: tee never binds positional closure params for stream inputs — {|x| $x | ignore } yields a VariableNotFoundAtRuntime error row. length used to silently swallow stream Value::Errors and count the error row, so the test passed with count 6 = 5 real rows + 1 masked error.

Now that length (and columns/is-empty) propagate stream errors (the point of this PR), that masked error surfaces, so the test legitimately fails.

I updated the test to use the working tee { $in | ignore } closure idiom and assert the true row count (5 instead of the count-6 that included the swallowed error). Product behavior is unchanged — the error transparency this PR adds is preserved, and the sqlite open/tee/flatten/length round-trip intent is the same. This also unmasks a pre-existing tee positional-param quirk worth a separate look.

Note: the workflow runs for the latest head show as action_required — they need a maintainer to click "Approve and run" (fork-PR approval gate) before checks start.

// inputs, which used to surface a `variable not found` error row that `length` swallowed and
// counted (6 = 5 rows + 1 masked error). Since `length` now propagates stream errors, use
// the `$in` idiom so the closure runs cleanly and the true row count (5) is reported.
#[case::tee("tee { $in | ignore } | flatten | length", 5)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe $in will collect here and stop streaming. I wonder if you could just have it as tee { ignore } instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call - referencing $in does collect the stream. Updated the test to ee { ignore } in 77f19a8 (comment updated to explain the no-argument closure choice).

Verified locally: all 64 sqlite_int_table_operations cases pass, including case_63_tee.

Reflect review feedback: a closure that references \ inside tee collects the stream, so use a no-argument closure (tee { ignore }) instead of tee { \ | ignore }.
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Sep 10, 2026
@fdncred
fdncred merged commit 5877cdf into nushell:main Sep 10, 2026
14 checks passed
@fdncred

fdncred commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Thanks

@github-actions github-actions Bot added this to the v0.116.0 milestone Sep 10, 2026
fdncred added a commit that referenced this pull request Nov 12, 2026
…19467)

## Description

A stream carries a failure as an item, so a command that read that item
and then dropped it also dropped the failure. `last`, `get 2`, `skip 1`
and others returned a normal result with exit code 0. This was the gap
#16738 and #18976 closed for collecting and for `length`, `columns` and
`is-empty`.

`exit` makes it worse. Since #18389 (0.114.0) `exit` travels as an error
instead of ending the process, so the same commands discarded it and the
script kept running. 0.113.1 exits 7 on the commands below, and 0.114.0
carries on with exit code 0.

Commands that read and drop an item now raise its error or pass it
along, and commands that bury an item in a record or list now pass the
error along instead. `;` no longer ignores an error returned as a single
value. A closure is never handed an `exit`, because `catch` can't handle
one and the closure could ignore it. `do --ignore-errors` no longer
ignores `exit`. Items that never ran stay unevaluated, so `first` and
`take` are as lazy as before.

## User-facing changes (Release notes)

- An error in a stream is no longer lost when a command drops that item.
This covers `last`, `get`, cell paths on a stream, `skip`, `skip while`,
`skip until`, `take while`, `take until`, `select`, `drop`, `drop nth`,
`slice`, `every`, `update`, `upsert`, `window`, `lines`, `zip` and `to
text`.
- `enumerate`, `wrap`, `zip`, `chunks`, `chunk-by`, `window` and `split
list` no longer hide a stream error inside the record or list they
build.
- An external now reports an error or `exit` in its input once it
finishes, so `boom | to text | ^cat` raises `boom` and `try` can catch
it. `do --ignore-errors` still ignores the error, but not `exit`.
- A closure that returns an error value now counts as failing in `take
while`, `take until`, `skip while`, `skip until`, `chunk-by`, `split
list` and `where`, where it used to count as `false`.
- `exit` inside a closure always ends the script again, whichever
command consumes the stream, and `do --ignore-errors` no longer ignores
it.
- `;` no longer discards an error returned as a single value, and
`catch` now sees errors from `first` and `last`.

### Breaking Changes
- a closure that fails in `take while`, `take until`, `skip while`,
`skip until`, `chunk-by` or `split list` now raises its error, as
`where` already does. It used to count as `false`, so `[{a: 1} {b: 2}] |
take while {|r| $r.a == 1 }` returned the first row and now reports the
missing column. Use `$r.a?` for optional columns.
- a script that relied on `last`, `skip` or similar to get past an error
now fails. To handle a failed item, use `each {|row| try { $row |
ignore; $row } catch { ... } }`.
- `reverse`, `shuffle`, `sort-by`, `drop` and `last` now raise an error
item instead of keeping it among the rows, so that `try` form has to
come before them.
- `to text` now raises an error instead of writing its debug form into
the text, and `each {|y| $y; 'ok' }` raises an error input instead of
discarding it at the `;`.

## Additional notes

Closes #19463
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

length, columns and is-empty silently consume error streams (gap after #16738)

2 participants