Skip to content

length, columns and is-empty silently consume error streams (gap after #16738) #18928

Closed

Description

@getreu

Describe the bug

When a where predicate raises a type error, where emits a stream of error values
rather than failing. Some downstream consumers propagate that error correctly, but
length, columns and is-empty silently consume the error values and return a
wrong answer with exit code 0.

The practical consequence is silent data loss: a pipeline can report that a filter
matched N rows and then produce nothing (or everything), with no error anywhere.

How to reproduce

# `size` is a filesize; `150` is an int. The comparison is a type error.
[[name size]; [a 100b] [b 200b]] | where size <= 150 | describe
# => list<error> (stream)

Consumers disagree about what to do with that stream:

pipeline expected actual
... | where size <= 150 | length error, or 1 2
... | where size <= 150 | columns error empty list
... | where size <= 150 | is-empty error false
... | where size <= 150 | first error error ✅
... | where size <= 150 | get name error error ✅
... | where size <= 150 | to json error error ✅
... | where size <= 150 | to nuon error error ✅

length returning 2 is the most damaging: it reports the unfiltered row count,
so the filter looks like it ran and matched everything.

The correct comparison behaves properly:

[[name size]; [a 100b] [b 200b]] | where size <= 150b | length
# => 1

Not specific to filesize — any incompatible predicate type does it:

[[d]; [1sec] [2sec]]   | where d <= 5 | length   # => 2
[[a]; ["x"] ["y"]]     | where a <= 5 | length   # => 2

Outside of where, the same comparison errors immediately, as expected:

100b <= 150
# Error: nu::shell::operator_incompatible_types
#   x Types 'filesize' and 'int' are not compatible for the '<=' operator.

Expected behavior

where should surface the predicate's type error. Failing that, every consumer of a
list<error> stream should propagate rather than silently counting or discarding the
error values.

How I found it

Filtering idx files (whose size column is a filesize) with an int bound:

idx files | where size <= 2000000 | length          # => 2466  (looks fine)
idx files | where size <= 2000000 | each { ... }    # => produces nothing
idx files | where size <= 2MB     | each { ... }    # => works

The length check reported all 2466 rows surviving the filter, so the filter appeared
correct, while the actual pipeline silently wrote an empty table and exited 0.

Configuration

version | 0.115.0
platform | x86_64-unknown-linux-gnu (NixOS, Linux 6.18.45)

Reproduced with nu --no-config-file.

Possibly related

Activity

  1. getreu commented on Aug 29, 2026

    @getreu
    Author

    Additional context after finding the prior art — this is narrower and more general
    than the original report suggests, so I've retitled it.

    where is incidental

    The same failure reproduces with no where involved:

    1..10 | each {|n| error make { msg: "x" } } | describe   # => list<error> (stream)
    1..10 | each {|n| error make { msg: "x" } } | length     # => 10
    1..10 | each {|n| error make { msg: "x" } } | columns    # => empty list
    1..10 | each {|n| error make { msg: "x" } } | is-empty   # => false

    length reporting 10 is the damaging one: it counts error values as though they
    were data.

    This is a gap left by #16738

    #16738 ("collecting a stream with an error raises an error", milestone v0.108.0) is
    working correctly on 0.115.0 — its release-note example errors as intended:

    let items = (1..10 | each {|n| error make { msg: "x" } })
    # Error: nu::shell::eval_block_with_input  ✅

    first propagates correctly too, for the same reason.

    But that guard only fires on collection into a value. length, columns and
    is-empty consume the stream without collecting it, so they never hit the check and
    silently return an answer computed from error values. The PR description says it
    "fixes similar bugs everywhere" — these three consumers appear to be the everywhere
    it didn't reach.

    Relationship to other issues

    The original where size <= 150 repro in the issue body still stands; it's just one
    way to manufacture the error stream rather than the defect itself.

    Tested on 0.115.0, nu --no-config-file.

  2. changed the title [-]`where` emits error values that `length`, `columns` and `is-empty` silently swallow[/-] [+]`length`, `columns` and `is-empty` silently consume error streams (gap after #16738)[/+] on Aug 29, 2026
  3. fdncred commented on Aug 31, 2026

    @fdncred
    Contributor

    Would like to see this fixed. Thanks!

  4. added a commit that references this issue on Sep 10, 2026
    5877cdf
  5. added this to the v0.116.0 milestone on Sep 10, 2026
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