Skip to content

Error is not propagated from a nested each #11224

@Veetaha

Description

@Veetaha

Potentially related (from @blm768):

Describe the bug

I tried this code:

[0] | each { |_|
    [0] | each { |_|
        non-existent-command
    }
}

If you put it into a file and run with nu you'll see the output:

╭───┬───────────────╮
│ 0 │ [list 1 item] │
╰───┴───────────────╯

If you put | debug after the outermost each you'll see:

╭───┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ 0 │ [EvalBlockWithInput(Span { start: 126475, end: 126476 }, [ExternalCommand { label: "executable was not found", help: "No such file or directory (os error    │
│   │ 2)", span: Span { start: 126499, end: 126519 } }])]                                                                                                          │
╰───┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

And if you put smth like | to json after the outermost each you'll see the error:

Details
Error: nu::shell::eval_block_with_input

  × Eval block failed with pipeline input
   ╭─[/home/veetaha/work/elastio/dbg.nu:5:1]
 5 │ [0] | each { |_|
 6 │     [0] | each { |_|
   ·      ┬
   ·      ╰── source value
 7 │         non-existent-command
   ╰────

Error: nu::shell::external_command

  × External command failed
   ╭─[/home/veetaha/work/elastio/dbg.nu:6:1]
 6 │     [0] | each { |_|
 7 │         non-existent-command
   ·         ──────────┬─────────
   ·                   ╰── executable was not found
 8 │     }
   ╰────
  help: No such file or directory (os error 2)

Expected behavior

I expected to see the "executable not found" error no matter what happens with the resulting value. The error should be propagated even if there is no | to json or similar at the end.

Configuration

key value
version 0.87.1
branch
commit_hash 3d63149
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.71.1 (eb26296b5 2023-08-03)
rust_channel 1.71.1-x86_64-unknown-linux-gnu
cargo_version cargo 1.71.1 (7f1d04c00 2023-07-29)
build_time 2023-11-18 18:51:59 +00:00
build_rust_channel release
allocator mimalloc
features default, sqlite, static-link-openssl, trash, which, zip
installed_plugins from eml, from ics, from ini, from vcf

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:error-handlingHow errors in externals/nu code are caught or handled programmatically (see also unhelpful-error)category:inconsistent-behaviorBehavior between different commands or types inconsistent/unexpectedstatus:needs-triageAn issue that hasn't had any proper look

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions