Description
Bug report form
- I have done a basic search of the issue tracker to find any existing issues that are similar.
- I have checked that my version is at least the latest stable release available via my installation method.
Describe the bug
last and get <n> silently drop error values from stream items they do not return. A pipeline that raised an error for a skipped item still succeeds, and an exit in that closure is discarded too.
first, length, and collect propagate the same error, so the result depends on which items the consumer reads. In the 0.116.1 source, last evicts rows from its buffer without checking for Value::Error, and get <n> collects the stream into a list and indexes it. Both bypass the error check that stream collection got in #16738, which looks like the remaining case of #18928 after #18976 fixed length, columns, and is-empty.
How to reproduce
[1 2 3] | each {|x| if $x == 1 { error make {msg: "boom"} }; $x } | last
# => 3, no error
[1 2 3] | each {|x| if $x == 1 { error make {msg: "boom"} }; $x } | get 2
# => 3, no error
[1 2 3] | each {|x| if $x == 1 { exit 1 }; $x } | last
# => 3, the script continues, and the process exits 0The error only surfaces when the failing item is the one returned:
[1 2 3] | each {|x| if $x == 3 { error make {msg: "boom"} }; $x } | last
# => Error: boom
[1 2 3] | each {|x| if $x == 1 { error make {msg: "boom"} }; $x } | get 0
# => Error: boomfirst and collect propagate it as well:
[1 2 3] | each {|x| if $x == 1 { error make {msg: "boom"} }; $x } | first
# => Error: boom
[1 2 3] | each {|x| if $x == 1 { error make {msg: "boom"} }; $x } | collect | last
# => Error: boomskip 1 on the same stream drops the error as well. Reproduced on 0.116.1 (latest release) and 0.112.2, both with --no-config-file.
Expected behavior
last, get <n>, and other consumers that discard items should propagate an error value even when the item holding it is not part of the result. An exit in a closure should not be discarded, so the script must not continue with exit code 0.
Configuration
| key | value |
|---|---|
| version | 0.116.1 |
| major | 0 |
| minor | 116 |
| patch | 1 |
| branch | |
| commit_hash | |
| build_os | linux-x86_64 |
| build_target | x86_64-unknown-linux-gnu |
| rust_version | rustc 1.99.0 (b940084d7 2026-09-28) (built from a source tarball) |
| cargo_version | cargo 1.99.0 (5f94df478 2026-08-27) |
| build_time | 1980-01-01 00:00:00 +00:00 |
| build_rust_channel | release |
| allocator | standard |
| features | dap, default, lsp, mcp, network, plugin, rustls-tls, sqlite, trash-support |
| installed_plugins | |
| experimental_options | example=false, dc-glob=false, reorder-cell-paths=true, pipefail=true, enforce-runtime-annotations=true, native-clip=false, cell-path-types=false |
Activity
kokhlo commentedon Nov 6, 2026
Traced both paths:
lastevicts rows from its ring buffer without checking forValue::Error(crates/nu-command/src/filters/last.rs, thebuf.pop_front()loop), andget <n>collects the stream with a plaincollect()before indexing (PipelineData::follow_cell_pathin nu-protocol), so an error in a skipped item stays dormant. Same class as what #18976 fixed forlength/columns/is-empty. I'll push a PR propagating the error in both, with regression tests, today.kokhlo commentedon Nov 6, 2026
PR up: #19466.
lastnow checks each row withValue::unwrap_error()before it can be evicted from the buffer, andget <n>collects the stream viaListStream::into_value()(which propagates the first error) instead of a plaincollect(). Verified all the cases from the report, includingexit:[1 2 3] | each {|x| if $x == 1 { exit 1 }; $x } | lastnow exits 1 instead of continuing with exit code 0 (andexit 3gives 3).skipis noted in the PR as a separate lazy-eager design question.kokhlo commentedon Nov 6, 2026
Update: the PR (#19466) now covers the
gethalf only. While testing I found thelasthalf conflicts with the semantics therecordfamily codified in #19190:[{a: {b: x}} {c: 1}] | record walk {|value, path| ... } | lastis expected to return the last good row, i.e.lastdeliberately skips error rows that mark failedrecord walkrows. Propagating errors from evicted rows would break those tests, so that part needs a semantics call from a maintainer (skip error rows vs. abort) rather than a fix here.skipis a similar lazy-vs-eager question.get <n>has no such conflict: skipped items are just not requested, and errors there are dropped purely by accident offollow_cell_pathcollecting the stream with a plain.collect()— the PR switches it toListStream::into_value(), which propagates the first error. Theexitcases from the report now work throughgetas well (exit 3in a skipped item exits 3).fdncred commentedon Nov 6, 2026
Please test #19467 and see if it covers these issues.
hakula139 commentedon Nov 10, 2026
Tested #19467 at 749aafc (built with
cargo build --release --no-default-features -p nu), and it covers these issues. Every case from the report now fails as expected:lastandget 2witherror makeon a skipped item exit 1 with the error.lastandget 2withexit 1orexit 3on a skipped item exit with that code.skip 1witherror makeorexit 3on a skipped item exits 1 or 3.get 0with an error after the requested index, andget 5?with an error on a skipped item, both exit 1.Laziness still holds:
firstwith an error on item 2 returns1,take 1returns[1], andlast 0returns[]without pulling items. On 0.116.1 and the 0.117.0 release, the same cases still print the surviving items and exit 0.docs(nushell): adopt project conventions (#21)
docs(nushell): address review findings on the conventions (#22)
fix: don't lose errors and `exit` from stream items a command drops (n…