Skip to content

fix(each): report the closure's error instead of "Eval block failed with pipeline input" - #19252

Merged
fdncred merged 1 commit into
nushell:mainfrom
fdncred:fix_each_error_headline
Oct 16, 2026
Merged

fdncred merged 1 commit into
nushell:mainfrom
fdncred:fix_each_error_headline

Conversation

@fdncred

@fdncred fdncred commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

The commands each, par-each, and items wrap an error raised by their closure in ShellError::EvalBlockWithInput. That variant had its own message, "Eval block failed with pipeline input", its own code, nu::shell::eval_block_with_input, and kept the closure's error in #[related]. So catch saw the wrapper's text, and the report printed the generic wrapper first and the error that mattered second:

> try { [1] | each { error make {msg: inner} } } catch {|e| $e.msg }
Eval block failed with pipeline input
> try { for x in [1] { error make {msg: inner} } } catch {|e| $e.msg }
inner

The variant now holds an EvalBlockWithInputError, a struct with a hand-written Diagnostic impl in crates/nu-protocol/src/errors/shell_error/eval_block_with_input.rs. It forwards to the wrapped error the same way ChainedError does for a single source, and adds one label.

User-facing changes (Release notes)

each reports the closure's error instead of "Eval block failed with pipeline input"

When a closure passed to each, par-each, or items fails, Nushell now reports the closure's error. The input value it was processing is shown as an extra source value label. $e.msg in catch is the closure's message, and the error code is the closure error's code instead of nu::shell::eval_block_with_input.

Before:

> [1 2] | each {|x| $x / 0 }
Error: nu::shell::eval_block_with_input

  × Eval block failed with pipeline input
   ╭─[source:1:2]
 1 │ [1 2] | each {|x| $x / 0 }
   ·  ┬
   ·  ╰── source value
   ╰────

Error: nu::shell::division_by_zero

  × Division by zero.
   ╭─[source:1:22]
 1 │ [1 2] | each {|x| $x / 0 }
   ·                      ┬
   ·                      ╰── division by zero
   ╰────

After:

> [1 2] | each {|x| $x / 0 }
Error: nu::shell::division_by_zero

  × Division by zero.
   ╭─[source:1:2]
 1 │ [1 2] | each {|x| $x / 0 }
   ·  ┬                   ┬
   ·  │                   ╰── division by zero
   ·  ╰── source value
   ╰────

Additional notes

Two fixes for code running inside these closures:

  • exit works. [1] | each { exit 4 } exits with 4, and try { [1] | each { exit 4 } } catch { ... } no longer runs the catch block.
  • An external's exit code survives. try { [1] | each { ^sh -c 'exit 42' } } catch {|e| $e.exit_code } is 42, and so is $env.LAST_EXIT_CODE.

Scripts that matched the code nu::shell::eval_block_with_input, or read $e.details.inner.0 to reach the closure's error, should use $e.msg / $e.details.msg instead

@github-actions github-actions Bot added the A:std-library Defining and improving the standard library written in Nu label Oct 15, 2026
@fdncred
fdncred merged commit c8095a3 into nushell:main Oct 16, 2026
12 checks passed
@fdncred
fdncred deleted the fix_each_error_headline branch October 16, 2026 11:12
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Oct 16, 2026
@github-actions github-actions Bot added this to the v0.117.0 milestone Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:std-library Defining and improving the standard library written in Nu notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant