Skip to content

Refactor each - #16732

Merged
Bahex merged 6 commits into
nushell:mainfrom
Bahex:refactor-each
Sep 23, 2025
Merged

Bahex merged 6 commits into
nushell:mainfrom
Bahex:refactor-each

Conversation

@Bahex

@Bahex Bahex commented Sep 21, 2025 •

Copy link
Copy Markdown
Member

Mostly clean up. Non-insignificant changes listed in release notes section:

  • If the closure returned a stream, errors in the stream were not properly chained and lost outer/caller context. They are now preserved.
  • Previously, each's behavior on ByteStream inputs differed from ListStream inputs with regards to error handling. Now they use the same implementation.
  • Possible performance increase due to lifting --keep-empty check out of the filter closure.

Release notes summary - What our users need to know

N/A

Tasks after submitting

N/A

the closures never return None
- add Value::unwrap_error
- dont imperatively push to a vec, use collect
- errors encountered during collecting ListStream werent properly 
  chained, lifting error chaining out of the match expression 
  deduplicates the code *and* fixes that
- early exit on empty inputs, *and* preserve metadata
This also fixes an (unnoticed) bug in the ByteStream arm
@Bahex

Bahex commented Sep 21, 2025

Copy link
Copy Markdown
Member Author

I need to write some tests (so we don't get regressions for the chained error in the future) before we can merge.

Pushed early to allow reviews.

@cptpiepmatz
cptpiepmatz self-requested a review September 22, 2025 17:18
@cptpiepmatz

Copy link
Copy Markdown
Member

I think the impl looks good, I'll wait with the approve until we have the tests.

@Bahex
Bahex merged commit 887767c into nushell:main Sep 23, 2025
@github-actions github-actions Bot added this to the v0.108.0 milestone Sep 23, 2025
Bahex added a commit to Bahex/nushell that referenced this pull request Sep 23, 2025
Sort of a follow up to nushell#16732, makes the stream-collecting error 
handling universal.
This fixes similar bugs everywhere.
WindSoilder pushed a commit that referenced this pull request Sep 24, 2025
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

> TODO(release-notes): Merge this with #16732's notes, this just
generalizes the fix for all commands.

## Tasks after submitting
N/A
@Bahex Bahex added A:error-handling How errors in externals/nu code are caught or handled programmatically (see also unhelpful-error) notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes notes:mention Noted in "Hall of Fame" section and removed notes:fixes Noted in "Bug fixes" section labels Oct 2, 2025
@Bahex
Bahex deleted the refactor-each branch March 22, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:error-handling How errors in externals/nu code are caught or handled programmatically (see also unhelpful-error) notes:mention Noted in "Hall of Fame" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants