Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

newlines near and causes conditionals to be treated like commands #12845

Open
MatrixManAtYrService opened this issue May 12, 2024 · 2 comments
Open
Labels
needs-triage An issue that hasn't had any proper look syntax Changes to the grammar or syntax beyond parser bugfixes unhelpful-error The error message you observe is not helpful to identify the problem

Comments

@MatrixManAtYrService
Copy link

MatrixManAtYrService commented May 12, 2024

First off, thanks for nushell. It's awesome.

Describe the bug

It's pretty jarring to have this work:

[{name: foo} {name: bar}] | where { |it|
  ($it.name == foo) and ($it.name != bar)
}
╭───┬──────╮
│ # │ name │
├───┼──────┤
│ 0 │ foo  │
╰───┴──────╯

...and then when you make one of those conditionals longer and decide to split them on separate lines for readability, it breaks:

[{name: foo} {name: bar}] | where { |it|
  $it.name == foo
  and $it.name != bar
}
Error: nu::shell::external_command

  × External command failed
   ╭─[entry #146:2:1]
 2 │ $it.name == foo
 3 │ and $it.name != bar
   · ─┬─
   ·  ╰── did you mean 'all'?
 4 │ }
   ╰────
  help: No such file or directory (os error 2)

Something about the new lines appears to be making and behave like a shell command, not a logical operator.

Expected behavior

I expect and to mean the same thing regardless of adjacent whitespace changes.

Screenshots

If you put round braces around the arguments to and you get the same error that you would if you ran: $ and true
Screenshot 2024-05-12 at 9 28 52 AM

Configuration

key value
version 0.87.1
branch
commit_hash
build_os macos-aarch64
build_target aarch64-apple-darwin
rust_version rustc 1.74.0 (79e9716c9 2023-11-13) (built from a source tarball)
cargo_version cargo 1.74.0
build_time 1980-01-01 00:00:00 +00:00
build_rust_channel release
allocator mimalloc
features default, sqlite, trash, which, zip
installed_plugins

Additional context

If altering and or the parsing isn't feasible, maybe users just need a nudge towards this syntax instead, which works fine.

[{name: foo} {name: bar}] | where (
  $it.name == foo
  and $it.name != bar
)
╭───┬──────╮
│ # │ name │
├───┼──────┤
│ 0 │ foo  │
╰───┴──────╯

I could imagine examples in help where and help and which would help users avoid this.

@MatrixManAtYrService MatrixManAtYrService added the needs-triage An issue that hasn't had any proper look label May 12, 2024
@MatrixManAtYrService MatrixManAtYrService changed the title and causes conditionals to be treated like commands newlines near and causes conditionals to be treated like commands May 12, 2024
@fdncred
Copy link
Collaborator

fdncred commented May 13, 2024

Does this issue still exist in the latest main? 0.87.1 is pretty old.

@merelymyself
Copy link
Contributor

Just tested - issue still exists on latest build.

@sholderbach sholderbach added syntax Changes to the grammar or syntax beyond parser bugfixes unhelpful-error The error message you observe is not helpful to identify the problem labels May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage An issue that hasn't had any proper look syntax Changes to the grammar or syntax beyond parser bugfixes unhelpful-error The error message you observe is not helpful to identify the problem
Projects
None yet
Development

No branches or pull requests

4 participants