Skip to content

Misleading error message if there is error inside else branch #7407

@kubouch

Description

@kubouch

Describe the bug

If there is an error in the else branch, the produced error is very unhelpful.

How to reproduce

> if false { 'a' } else { $foo }
Error: nu::parser::parse_mismatch (link)

  × Parse mismatch during operation.
   ╭─[entry #40:1:1]
 1 │ if false { 'a' } else { $foo }
   ·                       ────┬───
   ·                           ╰── expected one of a list of accepted shapes: [Block, Expression]
   ╰────

Compare to the output when there is an error in the if branch:

> if true { $foo } else { 'a' }
Error: nu::parser::variable_not_found (link)

  × Variable not found.
   ╭─[entry #41:1:1]
 1 │ if true { $foo } else { 'a' }
   ·           ──┬─
   ·             ╰── variable not found
   ╰────

Expected behavior

> if false { 'a' } else { $foo }
Error: nu::parser::parse_mismatch (link)

  × Parse mismatch during operation.
   ╭─[entry #40:1:1]
 1 │ if false { 'a' } else { $foo }
   ·                         ──┬─
   ·                           ╰── variable not found
   ╰────

Screenshots

No response

Configuration

key value
version 0.72.2
branch main
commit_hash b39d797
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.65.0 (897e37553 2022-11-02)
rust_channel 1.65.0-x86_64-unknown-linux-gnu
cargo_version cargo 1.65.0 (4bc8f24d3 2022-10-20)
pkg_version 0.72.2
build_time 2022-12-09 10:05:41 +02:00
build_rust_channel release
features database, dataframe, default, trash, which, zip
installed_plugins gstat

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:error-unhelpfulThe error message you observe is not helpful to identify the problemcategory:bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions