Repository navigation
fix: propagate error stream values in length, columns, and is-empty - #18976
Conversation
The previous tee closure used a positional param that is not bound for stream
inputs, surfacing a 'variable not found' error row that length used to swallow
and count (6 = 5 real rows + 1 masked error). Since length now propagates
stream errors, use the working 'tee { $in | ignore }' closure and assert the
true row count of 5.
ce37ef0 to
304e2f1
Compare
|
Heads-up on the CI failure from the Root cause: Now that I updated the test to use the working Note: the workflow runs for the latest head show as |
| // inputs, which used to surface a `variable not found` error row that `length` swallowed and | ||
| // counted (6 = 5 rows + 1 masked error). Since `length` now propagates stream errors, use | ||
| // the `$in` idiom so the closure runs cleanly and the true row count (5) is reported. | ||
| #[case::tee("tee { $in | ignore } | flatten | length", 5)] |
There was a problem hiding this comment.
I believe $in will collect here and stop streaming. I wonder if you could just have it as tee { ignore } instead?
There was a problem hiding this comment.
Good call - referencing $in does collect the stream. Updated the test to ee { ignore } in 77f19a8 (comment updated to explain the no-argument closure choice).
Verified locally: all 64 sqlite_int_table_operations cases pass, including case_63_tee.
Reflect review feedback: a closure that references \ inside tee collects the stream, so use a no-argument closure (tee { ignore }) instead of tee { \ | ignore }.
|
Thanks |
…19467) ## 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
Description
Fixes #18928.
length,columns, andis-empty/is-not-emptysilently consumedValue::Errorstream items instead of surfacing them, producing wrong silent results. For example,wherewith a type error could makelengthreport the unfiltered row count,columnsreturn[], oris-emptyreturn the wrong boolean.This PR makes all three commands propagate the first error encountered in the input stream:
length: theListStreamcount loop callsunwrap_error()on each value, returning the innerShellErrorinstead of counting it.columns: scans bothValue::ListandListStreaminputs forValue::Errorbefore computing columns, returning the inner error.is-empty/is-not-empty: theListStreamandValuebranches ofempty()return the inner error instead of treating an error item as non-empty.This is consistent with the error propagation that #16738 established for stream-collecting commands (
into_value,unwrap_error); these commands bypassed it with manual iteration.User-facing changes (Release notes)
length,columns, andis-emptynow surface errors from streamed inputFixed an issue where
length,columns, andis-empty/is-not-emptycould silently ignore errors in streamed input and return incorrect results instead of surfacing the original error.For example,
[[name size]; [a 100b] [b 200b]] | where size <= 150 | lengthnow errors withnu::shell::operator_incompatible_typesinstead of returning2, and likewise forcolumns/is-empty.Additional notes
Verification:
columnsreturnedList([])instead of erroring,lengthreturned the wrong count, andis-emptyreturned the wrong boolean.cargo fmt --check -p nu-command: cleancargo clippy -p nu-command --all-targets: cleannu-commandtests: 2884 pass, 22 fail due to pre-existing Windows symlink/privilege failures such ascan not create symlink: A required privilege is not held by the client, unrelated to this change.AI disclosure: this change was authored with the assistance of an AI coding agent.