Skip to content

record family of commands - #19190

Merged
fdncred merged 2 commits into
nushell:mainfrom
fdncred:record_commands
Oct 8, 2026
Merged

fdncred merged 2 commits into
nushell:mainfrom
fdncred:record_commands

Conversation

@fdncred

@fdncred fdncred commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR adds the record family 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 -d or items {..} | into record round trip. Each one also takes a table and streams one record per row.

record           help text listing the subcommands
record where     keep the fields where closure(key, value) is true    --keys --values
record each      rebuild the record from what closure(key, value) returns
record walk      run closure(value, path) on every nested leaf         --containers --no-lists
record apply     run a record of closures on the matching fields       --strict

User-facing changes (Release notes)

Work directly with records using the new record commands

Added record where, record each, record walk and record apply to 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. Run record to 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.

# keep the fields whose value is greater than one
{a: 1, b: 2, c: 3} | record where value > 1
# => {b: 2, c: 3}

# keep the fields whose key starts with NU_
{NU_LOG: debug, HOME: /home/me} | record where key starts-with NU_
# => {NU_LOG: debug}

# change keys and values in one pass
{a: 1, b: 2} | record each {|key, value| {($key | str uppercase): ($value * 10)}}
# => {A: 10, B: 20}

# redact nested values by their cell path
{db: {host: prod, password: hunter2}, api: {token: abc}} | record walk {|value, path|
    if ($path | to text) =~ "(?i)secret|token|password" { "***" } else { $value }
}
# => {db: {host: prod, password: ***}, api: {token: ***}}

# convert several fields with a reusable record of closures
{age: "42", email: "[email protected]", tags: [x]} | record apply {age: {into int}, email: {str lowercase}}
# => {age: 42, email: [email protected], tags: [x]}

# convert a column of every row of a table
[{name: a, size: "1"} {name: b, size: "2"}] | record apply {size: {into int}}
# => [[name, size]; [a, 1], [b, 2]]

record where accepts a row condition on key and value, or a closure receiving the key and value as arguments. Place --keys or --values before the condition to pass only the key or value. Use record walk --containers to also visit nested records and lists, or --no-lists to treat lists as single values. With record apply, --strict reports an error when a transform targets a field missing from the input.

Additional notes

closes #19061

@132ikl

132ikl commented Oct 8, 2026

Copy link
Copy Markdown
Member

it would be nice if record where could use row conditions, where this record where call (same as the closure example given):

{a: 1, b: 2, c: 3} | record where value > 1

roughly corresponds to the pipeline:

{a: 1, b: 2, c: 3} | transpose key value | where value > 1 | transpose -ird

@fdncred

fdncred commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

it would be nice if record where could use row conditions

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 record where key == blah or record where value == blah with any of the normal operators.

@fdncred

fdncred commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

row-condition is added to record where now as examples show.

@fdncred fdncred added notes:ready Indicates Ready for Release notes notes:additions Noted in "Additions" section labels Oct 8, 2026
@fdncred
fdncred merged commit 67edfb6 into nushell:main Oct 8, 2026
18 of 21 checks passed
@fdncred
fdncred deleted the record_commands branch October 8, 2026 23:49
@github-actions github-actions Bot added this to the 1.0 milestone Oct 8, 2026
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
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`
@hustcer hustcer modified the milestones: 1.0, v0.117.0 Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:additions Noted in "Additions" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Which record commands do we need?

3 participants