Skip to content

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

Closed

Description

@hakula139

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 0

The 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: boom

first 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: boom

skip 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

  1. kokhlo commented on Nov 6, 2026

    @kokhlo

    Traced both paths: last evicts rows from its ring buffer without checking for Value::Error (crates/nu-command/src/filters/last.rs, the buf.pop_front() loop), and get <n> collects the stream with a plain collect() before indexing (PipelineData::follow_cell_path in nu-protocol), so an error in a skipped item stays dormant. Same class as what #18976 fixed for length/columns/is-empty. I'll push a PR propagating the error in both, with regression tests, today.

  2. kokhlo commented on Nov 6, 2026

    @kokhlo

    PR up: #19466. last now checks each row with Value::unwrap_error() before it can be evicted from the buffer, and get <n> collects the stream via ListStream::into_value() (which propagates the first error) instead of a plain collect(). Verified all the cases from the report, including exit: [1 2 3] | each {|x| if $x == 1 { exit 1 }; $x } | last now exits 1 instead of continuing with exit code 0 (and exit 3 gives 3). skip is noted in the PR as a separate lazy-eager design question.

  3. kokhlo commented on Nov 6, 2026

    @kokhlo

    Update: the PR (#19466) now covers the get half only. While testing I found the last half conflicts with the semantics the record family codified in #19190: [{a: {b: x}} {c: 1}] | record walk {|value, path| ... } | last is expected to return the last good row, i.e. last deliberately skips error rows that mark failed record walk rows. 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. skip is 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 of follow_cell_path collecting the stream with a plain .collect() — the PR switches it to ListStream::into_value(), which propagates the first error. The exit cases from the report now work through get as well (exit 3 in a skipped item exits 3).

  4. fdncred commented on Nov 6, 2026

    @fdncred
    Contributor

    Please test #19467 and see if it covers these issues.

  5. hakula139 commented on Nov 10, 2026

    @hakula139
    Author

    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:

    • last and get 2 with error make on a skipped item exit 1 with the error.
    • last and get 2 with exit 1 or exit 3 on a skipped item exit with that code.
    • skip 1 with error make or exit 3 on a skipped item exits 1 or 3.
    • get 0 with an error after the requested index, and get 5? with an error on a skipped item, both exit 1.

    Laziness still holds: first with an error on item 2 returns 1, take 1 returns [1], and last 0 returns [] without pulling items. On 0.116.1 and the 0.117.0 release, the same cases still print the surviving items and exit 0.

  6. added this to the v0.118.0 milestone on Nov 12, 2026
  7. added a commit that references this issue on Nov 12, 2026
    6f51b1f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions