Repository navigation
refactor!: collecting a stream with an error raises an error - #16738
Merged
Merged
Conversation
Sort of a follow up to nushell#16732, makes the stream-collecting error handling universal. This fixes similar bugs everywhere.
Member
|
amazing! some are saying this is the best nushell PR yet |
132ikl
approved these changes
Sep 23, 2025
WindSoilder
approved these changes
Sep 24, 2025
WindSoilder
left a comment
Contributor
There was a problem hiding this comment.
Thanks! I love the change too
Merged
fdncred
pushed a commit
that referenced
this pull request
Sep 10, 2026
…18976) # Description Fixes #18928. `length`, `columns`, and `is-empty` (and `is-not-empty`) silently consumed `Value::Error` stream items instead of surfacing them, producing wrong, silent results (e.g. `where` with a type error → `length` reports the unfiltered row count, `columns` returns `[]`, `is-empty` returns the wrong boolean). Now all three 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 the `Value::List` and `ListStream` inputs for `Value::Error` before computing columns, returning the inner error (a list containing an error previously short-circuited `get_columns` to `[]`). - `is-empty` / `is-not-empty`: the `ListStream` and `Value` branches of `empty()` return the inner error instead of treating an error item as "not empty" (a bare `Value::Error` input previously fell through to `is_empty()` → `false`). This is consistent with the error propagation that #16738 established for stream-collecting commands (`into_value`, `unwrap_error`); these three commands bypassed it with manual iteration. ## Verification - Three new integration tests (one per command), all asserted to raise the propagated error. - Confirmed each test reproduces the bug pre-fix: - `columns` returned `List([])` instead of erroring - `length` returned the wrong count - `is-empty` returned the wrong boolean - Post-fix all pass. - `cargo fmt --check -p nu-command`: clean - `cargo clippy -p nu-command --all-targets`: clean - Full `nu-command` tests: 2884 pass, 22 fail — all pre-existing Windows symlink/privilege failures (e.g. `can not create symlink: A required privilege is not held by the client`), unrelated to this change. # User-Facing Changes `[[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`. # Tests + Formatting - Added tests under `crates/nu-command/tests/commands/` (`length.rs`, `empty.rs`, new `columns.rs`). - `cargo fmt --check` and `cargo clippy` clean as noted above. ## AI disclosure This change was authored with the assistance of an AI coding agent.
2 tasks done
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sort of a follow up to #16732, makes the stream-collecting error handling universal.
This fixes similar bugs everywhere.
Release notes summary - What our users need to know
Collecting a stream that contains errors now raises an error itself
Previously, if an error was returned as a stream item and you collected that stream into a value, you would and up with a list that has an
erroritem which you wouldn't know about until you interacted with that specific item.You could even end up with a list entirely made up of
errors:With this release that's no longer the case:
Simply attempting to collect such a stream immediately re-throws the first error encountered.
This also has the effect of preserving the context of errors raised some nested command calls like...
Errors raised in nested
eachcalls preserve their contextPreviously, errors raised in nested
eachcalls (and other commands that returned streams) could lose their outer/caller context.If the closure returned a stream, errors in the stream were not properly chained and lost this context. Running the following code:
we get:
Error Chain ANSI Output
Before:
After:
Tasks after submitting
N/A