Repository navigation
fix(each): report the closure's error instead of "Eval block failed with pipeline input" - #19252
Merged
Merged
Conversation
…ith pipeline input"
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
The commands
each,par-each, anditemswrap an error raised by their closure inShellError::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]. Socatchsaw the wrapper's text, and the report printed the generic wrapper first and the error that mattered second:The variant now holds an
EvalBlockWithInputError, a struct with a hand-writtenDiagnosticimpl incrates/nu-protocol/src/errors/shell_error/eval_block_with_input.rs. It forwards to the wrapped error the same wayChainedErrordoes for a single source, and adds one label.User-facing changes (Release notes)
eachreports the closure's error instead of "Eval block failed with pipeline input"When a closure passed to
each,par-each, oritemsfails, Nushell now reports the closure's error. The input value it was processing is shown as an extrasource valuelabel.$e.msgincatchis the closure's message, and the error code is the closure error's code instead ofnu::shell::eval_block_with_input.Before:
After:
Additional notes
Two fixes for code running inside these closures:
exitworks.[1] | each { exit 4 }exits with 4, andtry { [1] | each { exit 4 } } catch { ... }no longer runs thecatchblock.try { [1] | each { ^sh -c 'exit 42' } } catch {|e| $e.exit_code }is42, and so is$env.LAST_EXIT_CODE.Scripts that matched the code
nu::shell::eval_block_with_input, or read$e.details.inner.0to reach the closure's error, should use$e.msg/$e.details.msginstead