Repository navigation
record family of commands - #19190
Merged
Merged
Conversation
Member
|
it would be nice if {a: 1, b: 2, c: 3} | record where value > 1roughly corresponds to the pipeline: {a: 1, b: 2, c: 3} | transpose key value | where value > 1 | transpose -ird |
Contributor
Author
Good idea. Should any of they other commands use row-conditions? Probably not I'm guessing. It would probably be good to work with keys and values like |
Contributor
Author
|
|
Monster-GM
added a commit
to Monster-GM/nushell
that referenced
this pull request
Oct 10, 2026
Rebased onto current main and extended the missing-block fix so every runtime closure lookup reports an error instead of panicking: - convert the four `record` commands from nushell#19190 to the fallible constructors so main compiles again - add EngineState::get_closure_block as the single fallible lookup with a span and actionable help, replacing the six copied lookups and the public missing_block_error helper - give the ClosureEval / ClosureEvalOnce constructors a span argument so the error points at the failing call - make closure_arity fallible; it panicked before try_new ran in the tui hooks and preview - propagate the error from tee, with-env, explain, view source, the nu-cmd-base hook runner, and degrade gracefully in describe, the to text/toml/yaml/msgpack serializers and Closure::coerce_into_string - par-each checks the block once before consuming input, returning one error instead of one error value per item - default propagates the construction error instead of storing it as the default value - generate looks the block up once through try_new - new job regression tests: tee, par-each, record each, view source, describe --detailed, to text --serialize, and a combined test for with-env, explain, generate, record where/walk and sort-by
Monster-GM
added a commit
to Monster-GM/nushell
that referenced
this pull request
Oct 10, 2026
When a job is spawned before a later input is parsed, the job retains an older EngineState. The later closure's BlockId is therefore unavailable in that job, which previously panicked in EngineState::get_block. Closure evaluator construction is now fallible across all public entry points and every closure-consuming command propagates the error, so this condition returns 'Closure cannot be evaluated' with a span and actionable help instead of panicking. - remove the infallible ClosureEval / ClosureEvalOnce constructors and make every try_new* constructor take a span pointing at the failing call or closure value - add EngineState::get_closure_block as the single fallible lookup with a span and help text; direct get_block callers on runtime closure values (tee, with-env, explain, view source, record where, the hook runner and the tui closure_arity) now report the error too - degrade gracefully where a best-effort string is enough: describe --detailed, the to text / to toml / to yaml / to msgpack serializers and Closure::coerce_into_string - par-each checks the block once before consuming input (skipping empty input like each) instead of yielding one error value per item - default propagates the construction error instead of storing it as the default value - generate looks the block up once through try_new - convert the record commands from nushell#19190 to the fallible constructors - add regression tests that reproduce the interactive, multi-input job spawn / job send flow from nushell#19147 through do, each, zip, tee, par-each, record each, view source, describe --detailed, to text --serialize, and a combined test for with-env, explain, generate, record where, record walk and sort-by Fixes nushell#19147
2 tasks done
Monster-GM
added a commit
to Monster-GM/nushell
that referenced
this pull request
Oct 10, 2026
When a job is spawned before a later input is parsed, the job retains an older EngineState. The later closure's BlockId is therefore unavailable in that job, which previously panicked in EngineState::get_block. Closure evaluator construction is now fallible across all public entry points and every closure-consuming command propagates the error, so this condition returns 'Closure cannot be evaluated' with a span and actionable help instead of panicking. - remove the infallible ClosureEval / ClosureEvalOnce constructors and make every try_new* constructor take a span pointing at the failing call or closure value - add EngineState::get_closure_block as the single fallible lookup with a span and help text; direct get_block callers on runtime closure values (tee, with-env, explain, view source, record where, the hook runner and the tui closure_arity) now report the error too - degrade gracefully where a best-effort string is enough: describe --detailed, the to text / to toml / to yaml / to msgpack serializers and Closure::coerce_into_string - par-each checks the block once before consuming input (skipping empty input like each) instead of yielding one error value per item - default propagates the construction error instead of storing it as the default value - generate looks the block up once through try_new - convert the record commands from nushell#19190 to the fallible constructors - add regression tests that reproduce the interactive, multi-input job spawn / job send flow from nushell#19147 through do, each, zip, tee, par-each, record each, view source, describe --detailed, to text --serialize, and a combined test for with-env, explain, generate, record where, record walk and sort-by Fixes nushell#19147
Monster-GM
added a commit
to Monster-GM/nushell
that referenced
this pull request
Oct 10, 2026
When a job is spawned before a later input is parsed, the job retains an older EngineState. The later closure's BlockId is therefore unavailable in that job, which previously panicked in EngineState::get_block. Closure evaluator construction is now fallible across all public entry points and every closure-consuming command propagates the error, so this condition returns 'Closure cannot be evaluated' with a span and actionable help instead of panicking. - remove the infallible ClosureEval / ClosureEvalOnce constructors and make every try_new* constructor take a span pointing at the failing call or closure value - add EngineState::get_closure_block as the single fallible lookup with a span and help text; direct get_block callers on runtime closure values (tee, with-env, explain, view source, record where, the hook runner and the tui closure_arity) now report the error too - degrade gracefully where a best-effort string is enough: describe --detailed, the to text / to toml / to yaml / to msgpack serializers and Closure::coerce_into_string - par-each checks the block once before consuming input (skipping empty input like each) instead of yielding one error value per item - default propagates the construction error instead of storing it as the default value - generate looks the block up once through try_new - convert the record commands from nushell#19190 to the fallible constructors - add regression tests that reproduce the interactive, multi-input job spawn / job send flow from nushell#19147 through do, each, zip, tee, par-each, record each, view source, describe --detailed, to text --serialize, and a combined test for with-env, explain, generate, record where, record walk and sort-by Fixes nushell#19147
Monster-GM
added a commit
to Monster-GM/nushell
that referenced
this pull request
Oct 10, 2026
When a job is spawned before a later input is parsed, the job retains an older EngineState. The later closure's BlockId is therefore unavailable in that job, which previously panicked in EngineState::get_block. Closure evaluator construction is now fallible across all public entry points and every closure-consuming command propagates the error, so this condition returns 'Closure cannot be evaluated' with a span and actionable help instead of panicking. - remove the infallible ClosureEval / ClosureEvalOnce constructors and make every try_new* constructor take a span pointing at the failing call or closure value - add EngineState::get_closure_block as the single fallible lookup with a span and help text; direct get_block callers on runtime closure values (tee, with-env, explain, view source, record where, the hook runner and the tui closure_arity) now report the error too - degrade gracefully where a best-effort string is enough: describe --detailed, the to text / to toml / to yaml / to msgpack serializers and Closure::coerce_into_string - par-each checks the block once before consuming input (skipping empty input like each) instead of yielding one error value per item - default propagates the construction error instead of storing it as the default value - generate looks the block up once through try_new - convert the record commands from nushell#19190 to the fallible constructors - add regression tests that reproduce the interactive, multi-input job spawn / job send flow from nushell#19147 through do, each, zip, tee, par-each, record each, view source, describe --detailed, to text --serialize, and a combined test for with-env, explain, generate, record where, record walk and sort-by Fixes nushell#19147
Monster-GM
added a commit
to Monster-GM/nushell
that referenced
this pull request
Oct 10, 2026
When a job is spawned before a later input is parsed, the job retains an older EngineState. The later closure's BlockId is therefore unavailable in that job, which previously panicked in EngineState::get_block. Closure evaluator construction is now fallible across all public entry points and every closure-consuming command propagates the error, so this condition returns 'Closure cannot be evaluated' with a span and actionable help instead of panicking. - remove the infallible ClosureEval / ClosureEvalOnce constructors and make every try_new* constructor take a span pointing at the failing call or closure value - add EngineState::get_closure_block as the single fallible lookup with a span and help text; direct get_block callers on runtime closure values (tee, with-env, explain, view source, record where, the hook runner and the tui closure_arity) now report the error too - degrade gracefully where a best-effort string is enough: describe --detailed, the to text / to toml / to yaml / to msgpack serializers and Closure::coerce_into_string - par-each checks the block once before consuming input (skipping empty input like each) instead of yielding one error value per item - default propagates the construction error instead of storing it as the default value - generate looks the block up once through try_new - convert the record commands from nushell#19190 to the fallible constructors - add regression tests that reproduce the interactive, multi-input job spawn / job send flow from nushell#19147 through do, each, zip, tee, par-each, record each, view source, describe --detailed, to text --serialize, and a combined test for with-env, explain, generate, record where, record walk and sort-by Fixes nushell#19147
Monster-GM
added a commit
to Monster-GM/nushell
that referenced
this pull request
Oct 11, 2026
When a job is spawned before a later input is parsed, the job retains an older EngineState. The later closure's BlockId is therefore unavailable in that job, which previously panicked in EngineState::get_block. Closure evaluator construction is now fallible across all public entry points and every closure-consuming command propagates the error, so this condition returns 'Closure cannot be evaluated' with a span and actionable help instead of panicking. - remove the infallible ClosureEval / ClosureEvalOnce constructors and make every try_new* constructor take a span pointing at the failing call or closure value - add EngineState::get_closure_block as the single fallible lookup with a span and help text; direct get_block callers on runtime closure values (tee, with-env, explain, view source, record where, the hook runner and the tui closure_arity) now report the error too - degrade gracefully where a best-effort string is enough: describe --detailed, the to text / to toml / to yaml / to msgpack serializers and Closure::coerce_into_string - par-each checks the block once before consuming input (skipping empty input like each) instead of yielding one error value per item - default propagates the construction error instead of storing it as the default value - generate looks the block up once through try_new - convert the record commands from nushell#19190 to the fallible constructors - add regression tests that reproduce the interactive, multi-input job spawn / job send flow from nushell#19147 through do, each, zip, tee, par-each, record each, view source, describe --detailed, to text --serialize, and a combined test for with-env, explain, generate, record where, record walk and sort-by Fixes nushell#19147
Monster-GM
added a commit
to Monster-GM/nushell
that referenced
this pull request
Oct 16, 2026
When a job is spawned before a later input is parsed, the job retains an older EngineState. The later closure's BlockId is therefore unavailable in that job, which previously panicked in EngineState::get_block. Closure evaluator construction is now fallible across all public entry points and every closure-consuming command propagates the error, so this condition returns 'Closure cannot be evaluated' with a span and actionable help instead of panicking. - remove the infallible ClosureEval / ClosureEvalOnce constructors and make every try_new* constructor take a span pointing at the failing call or closure value - add EngineState::get_closure_block as the single fallible lookup with a span and help text; direct get_block callers on runtime closure values (tee, with-env, explain, view source, record where, the hook runner and the tui closure_arity) now report the error too - degrade gracefully where a best-effort string is enough: describe --detailed, the to text / to toml / to yaml / to msgpack serializers and Closure::coerce_into_string - par-each checks the block once before consuming input (skipping empty input like each) instead of yielding one error value per item - default propagates the construction error instead of storing it as the default value - generate looks the block up once through try_new - convert the record commands from nushell#19190 to the fallible constructors - add regression tests that reproduce the interactive, multi-input job spawn / job send flow from nushell#19147 through do, each, zip, tee, par-each, record each, view source, describe --detailed, to text --serialize, and a combined test for with-env, explain, generate, record where, record walk and sort-by Fixes nushell#19147
Monster-GM
added a commit
to Monster-GM/nushell
that referenced
this pull request
Oct 16, 2026
When a job is spawned before a later input is parsed, the job retains an older EngineState. The later closure's BlockId is therefore unavailable in that job, which previously panicked in EngineState::get_block. Closure evaluator construction is now fallible across all public entry points and every closure-consuming command propagates the error, so this condition returns 'Closure cannot be evaluated' with a span and actionable help instead of panicking. - remove the infallible ClosureEval / ClosureEvalOnce constructors and make every try_new* constructor take a span pointing at the failing call or closure value - add EngineState::get_closure_block as the single fallible lookup with a span and help text; direct get_block callers on runtime closure values (tee, with-env, explain, view source, record where, the hook runner and the tui closure_arity) now report the error too - degrade gracefully where a best-effort string is enough: describe --detailed, the to text / to toml / to yaml / to msgpack serializers and Closure::coerce_into_string - par-each checks the block once before consuming input (skipping empty input like each) instead of yielding one error value per item - default propagates the construction error instead of storing it as the default value - generate looks the block up once through try_new - convert the record commands from nushell#19190 to the fallible constructors - add regression tests that reproduce the interactive, multi-input job spawn / job send flow from nushell#19147 through do, each, zip, tee, par-each, record each, view source, describe --detailed, to text --serialize, and a combined test for with-env, explain, generate, record where, record walk and sort-by Fixes nushell#19147
fdncred
pushed a commit
that referenced
this pull request
Oct 16, 2026
## Description When a job is spawned before a later input is parsed, the job retains an older `EngineState`. The later closure's `BlockId` is therefore unavailable in that job, which previously panicked in `EngineState::get_block`. - remove the infallible `ClosureEval` / `ClosureEvalOnce` constructors and make every `try_new*` constructor take a span pointing at the failing call or closure value, so a stale `BlockId` can no longer panic through any entry point (`do`, `each`, `zip`, `where`, …) - add `EngineState::get_closure_block` as the single fallible lookup with a span and actionable help (shared `MISSING_CLOSURE_BLOCK_HELP` const); direct `get_block` callers on runtime closure values (`tee`, `with-env`, `export-env`, `explain`, `view source`, `record where`, `job spawn`, `debug profile`, the hook runner and the tui `closure_arity`) now report the same error instead of panicking - `debug profile` checks the block before installing the profiler, and `job spawn` checks before registering the job, so the error reaches the caller's `try`/`catch` instead of the background thread - best-effort consumers degrade instead of panicking: `describe --detailed` omits the `signature` key, `to text` / `to toml --serialize` fall back to the existing placeholder string, `to yaml --serialize` returns the `closure_block_not_found` error, and `Closure::coerce_into_string` (`to msgpack`, `to kdl`) returns `CantConvert` - `par-each` builds the evaluator once in `run` (skipping empty input like `each`) and clones it into the workers, returning a single error instead of one error value per item - `default` propagates the construction error instead of storing it as the default value - `generate` reads the signature from the evaluator's `block()` instead of looking the block up twice - `ClosureEval` / `ClosureEvalOnce` expose `block()`, removing the remaining second lookups in `record where`, the tui `call_closure` and `generate` - convert the `record` commands from #19190 to the fallible constructors - add regression tests that reproduce the interactive, multi-input `job spawn` / `job send` flow from #19147 through `do`, `each`, `zip`, `tee`, `par-each`, `record each`, `view source`, `describe --detailed`, `to text --serialize`, `debug profile`, `job spawn`, and a combined test for `with-env`, `explain`, `generate`, `record where`, `record walk` and `sort-by` Removing the infallible constructors is a breaking change to nu-engine's public API without a deprecation step: a deprecated shim cannot avoid the panic, which is what this PR removes, so the break is intentional. ## User-facing changes (Release notes) - Fixed an issue where a closure created after a job was spawned panicked the job when used (`do`, `each`, `zip`, `tee`, `par-each`, `sort-by`, `explain`, `with-env`, `job spawn`, …). Nushell now reports `Closure cannot be evaluated` with a span and a hint instead, and `job spawn` / `debug profile` now surface the error to the caller. - Serializing such a closure no longer crashes: `describe --detailed` and `to text` / `to toml --serialize` degrade to the existing placeholder, while `to yaml --serialize` and `to msgpack` report a conversion error. ## Additional notes - fixes #19147 - rebase note: this branch now includes the conversion of the `record` commands merged in #19190, which called the removed constructors ## Validation - `cargo test -p nu-command --test tests job` (44 passed; do / each / zip / tee / par-each / record each / record where / record walk / view source / describe / to text / debug profile / job spawn / with-env / explain / generate / sort-by scenarios) - `cargo test -p nu-command --test tests` (3438 passed; the 21 failures are pre-existing Windows symlink-privilege environment failures, confirmed identical on upstream main) - `cargo test` for nu-engine, nu-cmd-lang, nu-protocol, nu-tui, nu-cmd-base, nu-color-config, nu-heavy-utils, nu-cli, nu-cmd-extra, nu-lsp, nu-dap, nu-plugin-engine (only the same symlink-privilege failures, confirmed on upstream main) - `cargo test -p nu-engine --doc`, `cargo test -p nu-protocol --doc` - `cargo fmt --all -- --check` - `cargo clippy -p nu-engine -p nu-cmd-lang -p nu-command -p nu-cli -p nu-cmd-extra -p nu-color-config -p nu-plugin-engine -p nu-tui -p nu-protocol -p nu-cmd-base -p nu-heavy-utils --tests --no-deps -- -D warnings`
This was referenced Nov 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds the
recordfamily of commands that makes working with records easier and more fun.There are four record commands as discussed in #19061. Each one takes a record and returns a record, so the common jobs no longer need a
transpose k v | ... | transpose -r -doritems {..} | into recordround trip. Each one also takes a table and streams one record per row.User-facing changes (Release notes)
Work directly with records using the new
recordcommandsAdded
record where,record each,record walkandrecord applyto filter fields, transform keys and values, process nested values, and apply field-specific conversions without converting records to tables and back. Each command also accepts a table and streams one record per row. Runrecordto see help listing the subcommands.The following examples show how to filter and transform records, redact nested values, and convert fields in records or table rows.
record whereaccepts a row condition onkeyandvalue, or a closure receiving the key and value as arguments. Place--keysor--valuesbefore the condition to pass only the key or value. Userecord walk --containersto also visit nested records and lists, or--no-liststo treat lists as single values. Withrecord apply,--strictreports an error when a transform targets a field missing from the input.Additional notes
closes #19061