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

Confusing error message when or parenthesis is missing #7405

Open
domenkozar opened this issue Dec 5, 2022 · 12 comments
Open

Confusing error message when or parenthesis is missing #7405

domenkozar opened this issue Dec 5, 2022 · 12 comments
Labels
bug error-messages Confusing messages and better diagnostics language The Nix expression language; parser, interpreter, primops, evaluation, etc

Comments

@domenkozar
Copy link
Member

domenkozar commented Dec 5, 2022

nix-repl> {a = 3;}.a or throw "what"  
error: attempt to call something which is not a function but an integer

       at «string»:1:1:

            1| {a = 3;}.a or throw "what"
             | ^

I lost about an hour trying to understand what's going on and that it needs parenthesis like (throw "what")

See #629

cc @bburdette

@domenkozar domenkozar added bug error-messages Confusing messages and better diagnostics labels Dec 5, 2022
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/what-would-you-like-to-see-improved-in-nix-cli-experience/24012/6

@tejing1
Copy link

tejing1 commented Dec 14, 2022

Oh wow. How is or higher precedence than function application? That seems like a very bad language design choice.

@roberth
Copy link
Member

roberth commented Dec 17, 2022

and... I DID IT AGAIN. Should have been me opening this issue because I keep repeating this mistake.

@tejing1

very bad

Fwiw, there's no or operator; only the _ . _ or _ ternary operator, with the same priority as _ . _.

That's not a good excuse though; I agree.

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nix-interpreter-and-nix-language-quirks/25117/2

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nix-interpreter-and-nix-language-quirks/25117/3

@jeff-hykin
Copy link

jeff-hykin commented Apr 30, 2023

It'd be really nice if the or operator was documented on https://nixos.wiki/wiki/Overview_of_the_Nix_Language

After seeing the "or" operator last year I spent quite a while trying to figure out what it was and how it worked and found absolutely nothing. Happened to come across this thread while searching something else.

@roberth roberth added the language The Nix expression language; parser, interpreter, primops, evaluation, etc label May 17, 2023
@roberth roberth changed the title Confusing error message when parenthesis is missing Confusing error message when or parenthesis is missing May 17, 2023
@roberth
Copy link
Member

roberth commented May 17, 2023

Mentioning ExprSelect, the relevant AST node here so that this issues shows up in search.

@jeff-hykin
Copy link

jeff-hykin commented May 17, 2023

As an update: I see now, technically the operator is mentioned, but I was working on an improved syntax highlighter for nix (meaning I was reading that page over and over trying to find exact specifications for all operators) and I still misinterpreted it, so I think pretty much everyone is going to miss it in it's current form.

Screen Shot 2023-05-17 at 10 52 35 AM

With the or being inside of the []'s it seems like its being used as some sort of description piece, like e . attrpath [and/or default] rather than an operator. Its also unclear if the []'s are a literal operator themselves or just markup.

Syntax highlighting on the examples would be a tremendous help, because even being outside of the []'s e.g. e . attrpath or default it sill reads a lot like a descriptor given there are no other word-like operators in the list.

Without a full example explaining how it works, and/or some text somewhere with "or operator" to make it search-friendly I think it'll continue to be really confusing. Splitting up the example into e . attrpath and e . attrpath or default would probably also help.

@roberth
Copy link
Member

roberth commented May 17, 2023

Feel free to split that row into two rows on the wiki. I'm sure that will be clearer.

improved syntax highlighter for nix

If it's feasible to express this in the grammar-like construct you're probably using, you could perhaps highlight it in red or yellow when any occurrence of e . a or e1 e2 isn't written as (e . a or e1) e2?

@jeff-hykin
Copy link

Alright, I did my best to clear it up on the Wiki.

In this base version of syntax highligher, I prefer not to impose any style preferences when the code is executable. I'll just make sure that "or" is not highlighted when its not a part of the ternary operation. Maybe I can make an opinionated version that highlights e . a or e1 e2 as problematic.

@roberth
Copy link
Member

roberth commented May 18, 2023

Yeah, it's just an idea. Where will your highlighter be used?

@jeff-hykin
Copy link

jeff-hykin commented May 19, 2023

It's a textmate highlighter so it can be adapted to a lot of editors/runtimes, but it'll be packaged up in a VS Code/VS Codium extension.

I'm the maintainer for the C++ and Shell syntax of VS Code, so if I can make a good one for nix I was going to reach out to some of my Microsoft contacts and see if it could become part of the built-in language support. There's a few things I wanted to do different than the exisitng syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug error-messages Confusing messages and better diagnostics language The Nix expression language; parser, interpreter, primops, evaluation, etc
Projects
None yet
Development

No branches or pull requests

5 participants