Skip to content

fix: don't lose errors and exit from stream items a command drops - #19467

Merged
fdncred merged 4 commits into
nushell:mainfrom
fdncred:stream_error_propagation
Nov 12, 2026
Merged

fdncred merged 4 commits into
nushell:mainfrom
fdncred:stream_error_propagation

Conversation

@fdncred

@fdncred fdncred commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

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

@fdncred

fdncred commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@Tyarel8 I believe you had a change in this same area recently. Would you mind testing this to make things still work as expected?

@Tyarel8

Tyarel8 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

@Tyarel8 I believe you had a change in this same area recently. Would you mind testing this to make things still work as expected?

I have tried it a bit and seems to be working fine 👍

@fdncred

fdncred commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. I just wanted to make sure that I didn't accidentally undo your changes.

hakula139 added a commit to hakulab/plugins that referenced this pull request Nov 10, 2026
## Summary

Two projects documented general Nushell conventions in their own
`docs/conventions/nushell.md`, and the nushell skill now holds them,
worded without project names, so those pages can keep only their
project-specific rules:

- **Scripts:** export only what another module or the module's own test
calls, layer imports one way from the entry through domain modules to
generic helpers, import a module by name when its commands share verbs
with siblings and otherwise list the imported commands, and order a
module's sections as the pipeline first reaches them with callees before
callers. The Quoting bullet now makes double quotes the default, with
single quotes for text holding a literal backslash or double quote, as a
regex does, which agrees with the dynamic regex trap.
- **Testing:** tests sit beside their module as `<module>.test.nu`, an
entry script runs through `^$nu.current-exe`, an assertion compares the
whole shape the test owns, and fixtures use a fixed day in UTC while the
test sets `TZ` for the child process.
- **Linting:** don't format with `nufmt`. It reindents to four spaces by
default, and even with `indent: 2` it joins a pipeline split one stage
per line, or a call split one option per line, onto one line, against
the code-layout skill.

The stream trap now names `skip` beside `get <n>` and `last`, since it
too runs and discards a skipped item's error, and links the upstream
issue, nushell/nushell#19463. Its fix, nushell/nushell#19467, is in no
release yet.

The skill had grown long, so a second commit groups it under task
headings without changing a bullet: Scripts splits into entry and help,
modules and imports, layout and order, quoting and strings, and paths.
The two long trap groups split into `####` subsections, and Testing into
layout and assertions, inputs and fixtures, and the nu-test runner. No
link in this repository or in devkit points at an anchor in the skill.

Project-specific items stay in their projects: module lists and
dependency graphs, external tools, the config record, real `git init`
repositories, the `edit-file` and file-URI `url encode` traps, and the
`$env.HOME` override.

Bump hakula-languages to 1.0.6, and add `nufmt` to the spelling
dictionary.

## Test plan

- [x] Commit and push hooks
- [x] `nix develop -c run-hooks`
- [x] `nix flake check --all-systems`
- [x] `claude plugin validate .`
- [x] On Nushell 0.116.1, `$nu.current-exe` names the dev shell's `nu`,
the same path as `which nu`
- [x] A child started with `with-env {TZ: ...} { ^$nu.current-exe
entry.nu }` formats `date now` in that zone: `+00:00` for `UTC`,
`+09:00` for `Asia/Tokyo`, and `-05:00` for `America/New_York`
- [x] With `use ./cache.nu` and `use ./index.nu`, `cache read` and
`index read` both resolve, `use ./paths.nu [path-map path-match]` leaves
an unlisted export undefined, and `use ./cache.nu *` leaves a
non-exported helper undefined
- [x] `'a\d' == "a\\d"` and `'say "hi"' == "say \"hi\""` hold, and
`"\d+"` fails to parse with `unrecognized escape sequence`
- [x] `assert equal` fails on an extra record field and on an extra
table row
- [x] `nix shell nixpkgs#nufmt -c nufmt` (0.1.0) reindents a two-space
file to four spaces, and with `{indent: 2}` as its config it still joins
a split pipeline and a split `^git log` call onto one line each
- [x] `[1 2 3] | each {|x| if $x == 1 { error make {msg: boom} } else {
$x } } | skip 1 | to nuon` prints `[2, 3]` and exits 0
- [x] The reorganization changes no content line, since the sorted
non-heading lines before and after it are identical. Against `main`, the
sorted bullet labels differ only by the six added here (Assertions,
Imports, Layout, Modules, Order, and Timestamps) and the stream trap's
head that now names `skip`
hakula139 added a commit to hakulab/plugins that referenced this pull request Nov 10, 2026
## Summary

The nushell skill's stream trap now states the general pattern behind
it, the traps gain a top-level syntax section and a separate environment
section, and several examples and labels match the skill's own rules.

- **Stream errors:** the trap now covers any command that pulls a stream
item and discards it, which drops that item's `exit` or `error make`,
with `get <n>`, `last`, `skip`, `drop`, and `select` as examples. It
keeps the
[nushell/nushell#19463](nushell/nushell#19463)
link, points to
[nushell/nushell#19467](nushell/nushell#19467)
for the full list of affected commands, and adds `collect` before the
command as the way to surface the error, while `first` stays the way to
take a single match.
- **Quoting example:** `into datetime --format "%s"` uses double quotes,
as the skill's quoting rule asks. The remaining single-quoted examples
hold a backslash (the regex piece), name the `$'...'` syntax, or show
script arguments as shell input.
- **Trap sections:** `### Syntax` now opens the traps, `### Parsing and
data` becomes `### Data and types` with its `#### Streams and commands`
renamed to `#### Commands`, and the `$nu.home-dir` trap moves into its
own `### Environment` after External commands.
- **Test files:** the **Layout** bullet becomes **Location** and names
the file `<name>.test.nu`, matching the runner's `<name>.stub.nu`, and
its subsection becomes "Files and assertions".
- **Module order:** sections follow the order the entry first calls
them, and the sentence on test-file order is gone, since the code-layout
skill already orders tests by the code's order.
- **Imports example:** the listed commands use invented names, `use
./paths.nu [path-split path-label]`.
- **Timestamps:** the bullet now gives the reason a test sets `TZ` for
the child process, since the running Nushell reads its zone only at
startup.

Bump hakula-languages to 1.0.7.

## Test plan

- [x] Commit and push hooks, and `nix develop -c run-hooks`
- [x] `nix flake check --all-systems`
- [x] `claude plugin validate .`
- [x] On the dev shell's Nushell 0.116.1, with `mk n` as `[1 2 3] | each
{|x| if $x == n { error make {msg: boom} } else { $x } }`, `mk 3 | drop
1`, `mk 1 | select 1`, `mk 1 | skip 1`, `mk 1 | get 2`, `mk 1 | last`,
`mk 1 | last 2`, and `mk 1 | drop nth 0` print results and exit 0, while
`mk 1 | collect | skip 1`, `mk 3 | collect | drop 1`, and `mk 1 |
collect | last` raise `boom`
- [x] With a host zone of `+0800`, `$env.TZ = "Asia/Tokyo"` and
`with-env {TZ: "Asia/Tokyo"} { date now | format date "%z" }` still
print `+0800` in-process, while a child `^$nu.current-exe` under the
same `with-env` prints `+0900`
- [x] GitHub CI: Linux, macOS, and CI Result
…ation

# Conflicts:
#	crates/nu-cli/src/util.rs
#	crates/nu-cmd-lang/src/core_commands/do_.rs
#	crates/nu-command/src/bytes/ends_with.rs
#	crates/nu-command/src/filters/chunks.rs
#	crates/nu-command/src/filters/last.rs
#	crates/nu-protocol/src/errors/shell_error/bridge.rs
#	crates/nu-protocol/src/pipeline/byte_stream.rs
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes and removed status:wait-until-after-nushell-release labels Nov 12, 2026
@fdncred
fdncred merged commit 6f51b1f into nushell:main Nov 12, 2026
18 of 21 checks passed
@fdncred
fdncred deleted the stream_error_propagation branch November 12, 2026 20:03
@github-actions github-actions Bot added this to the v0.118.0 milestone Nov 12, 2026
fdncred added a commit that referenced this pull request Nov 24, 2026
…`tee` (#19647)

## Description


Since 0.114.0, `try` skips `catch` when it's piped into `ignore`,
`complete`, `save` or `tee` and the error comes from the last command in
its block. `finally` still runs, but it gets the raw error as its input
and parameter, so the first command there that reads either one raises
the error again. The case most likely to bite is a custom command that
ends in a `try`. Call it as `my-command | ignore` and its `catch` never
runs.

#18306 made a command return its error as a value when its stderr goes
to a separate pipe. That lets `ignore --stderr` decide what to do with
the error. All four commands above ask for that separate pipe, and the
last command in a `try` block inherits the redirection of whatever
follows the `try`. So the error turned into a value, passed through
`try` without reaching `catch`, and the next command raised it. Up to
0.117.0, a `;` after the pipeline discarded the error. #19467 stopped
that, so on main the error surfaces.

`try` now raises an error value that reaches the end of its block, or
the end of `catch` before `finally`. The handlers run the same as they
do without the pipe. When only `finally` handles the error, `finally`
gets the error record. Then the error goes on to the next command as a
value, the same as without `finally`, so `ignore --stderr` still
consumes it.


## User-facing changes (Release notes)

- Fixed `try` skipping `catch` when it's piped into `ignore`,
`complete`, `save` or `tee`, including through a custom command that
ends in a `try`. In the same case `finally` now gets the error record
instead of the raw error. This was a regression in 0.114.0.
- `try { ... } catch { 'fallback' } | ignore --stderr` now passes on
`fallback` instead of consuming the error, and `try { exit 3 } | ignore
--stderr` now exits.

## Additional notes
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.

last and get <n> silently drop stream errors from items they skip

2 participants