Skip to content

Error is not propagated from a nested each #11224

Closed

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

Activity

  1. added
    status:needs-triage
    on Dec 4, 2023
  2. added
    A:error-handling
    category:inconsistent-behavior
    on Dec 4, 2023
  3. amtoine commented on Dec 4, 2023

    @amtoine
    Member

    yeah, not sure what's happening there 🤔

    looks like errors are partially values and partially thrown??
    if you put it in a variable, it's fine

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

    if you look at the variable, it's fine

    $foo

    but if you try to look at the list item, now it throws the error 😮

    $foo.0
    
  4. blm768 commented on Dec 11, 2023

    @blm768

    Potentially related: #10176, #8615.

  5. added a commit that references this issue on May 1, 2024
    b22d131
  6. added this to the v0.94.0 milestone on May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:error-handlingcategory:inconsistent-behaviorstatus:needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions