Repository navigation
Open
Labels
A:error-handlingHow errors in externals/nu code are caught or handled programmatically (see also unhelpful-error)
Description
Describe the bug
An error in an each loop does not stop the loop, and when used in a nu script, does not stop the program.
How to reproduce
❯ [1 2 3] | each { |n| print $n; error make {msg: "stop!"} }
1
2
3
Error: nu::shell::eval_block_with_input
× Eval block failed with pipeline input
╭─[entry #269:1:1]
1 │ [1 2 3] | each { |n| print $n; error make {msg: "stop!"} }
· ┬
· ╰── source value
╰────
Error:
× stop!
╭─[entry #269:1:1]
1 │ [1 2 3] | each { |n| print $n; error make {msg: "stop!"} }
· ─────┬────
· ╰── originates from here
╰────When this is in a nu script, it does not cause the process to return a non-zero exit code, which is especially bad when using nushell scripts within complex pipelines (such as in a build system).
Create a file junk.nu with the following contents.
#!/usr/bin/env nu
def main [] {
[1 2 3] | each { |n| print $n; error make {msg: "stop!"} }
}Set the executable bit on it, and then in a bash shell, run it.
❯ ./junk.nu
1
2
3
Error: nu::shell::eval_block_with_input
× Eval block failed with pipeline input
╭─[/home/aidan/junk.nu:3:1]
3 │ def main [] {
4 │ [1 2 3] | each { |n| print $n; error make {msg: "stop!"} }
· ┬
· ╰── source value
5 │ }
╰────
Error:
× stop!
╭─[/home/aidan/junk.nu:3:1]
3 │ def main [] {
4 │ [1 2 3] | each { |n| print $n; error make {msg: "stop!"} }
· ─────┬────
· ╰── originates from here
5 │ }
╰────
~
❯ echo $?
0Expected behavior
Something more like this, where only the first print is executed, and then the error immediately after terminates the entire loop.
❯ [1 2 3] | each { |n| print $n; error make {msg: "stop!"} }
1
Error: nu::shell::eval_block_with_input
× Eval block failed with pipeline input
╭─[entry #1:1:1]
1 │ [1 2 3] | each { |n| print $n; error make {msg: "stop!"} }
· ┬
· ╰── source value
╰────
Error:
× stop!
╭─[entry #1:1:1]
1 │ [1 2 3] | each { |n| print $n; error make {msg: "stop!"} }
· ─────┬────
· ╰── originates from here
╰────
And when run in a script, for the exit code to be non-zero.
Screenshots
No response
Configuration
| key | value |
|---|---|
| version | 0.77.0 |
| branch | |
| commit_hash | |
| build_os | linux-x86_64 |
| build_target | x86_64-unknown-linux-gnu |
| rust_version | rustc 1.67.1 (d5a82bbd2 2023-02-07) (built from a source tarball) |
| cargo_version | cargo 1.67.0 |
| build_time | 1980-01-01 00:00:00 +00:00 |
| build_rust_channel | release |
| features | default, zip |
| installed_plugins |
Additional context
No response
Reacted by Reilly Wood, Taylor, Harper Andrews, Jochem and Clément Nerma
Metadata
Metadata
Assignees
Labels
A:error-handlingHow errors in externals/nu code are caught or handled programmatically (see also unhelpful-error)
Activity
tv42 commentedon Dec 11, 2023
Related.. I think these are all aspects of the same underlying problem: #10633, #10856
kronberger-droid commentedon Nov 13, 2026
Half of this is fixed: the exit code is 1 now.
The loop still runs all items when the result goes to the display on 0.117:
prints
1,2,3and only then the error.With
| ignoreor aletit stops after the first item.