oxalica / nil

NIx Language server, an incremental analysis assistant for writing in Nix.
Apache License 2.0
1.28k stars 39 forks source link

Wrong return code on nil diagnostics #129

Closed nalves599 closed 3 months ago

nalves599 commented 5 months ago

When I run nil diagnostics <file-name> on a file with only warnings the help util says:

Exit with non-zero code if there are any diagnostics. (1 for errors, 2 if only warnings)

But when there are only warnings it returns 0.

image

The bug might be in this piece of code

tennox commented 3 months ago

Hey there, just stumbled on this randomly, and I'm also the author of the code you're referring to.

It's in fact the wanted behaviour we ended up deciding for in this discussion - gist:

To me, warnings should not be errors. We can just change the default behavior here to make it returns non-zero only on errors. Users who want the old deny-all behavior can still check if stdout is empty anyway. What do you think?

I did in fact, forget to update the help/documentation I had changed before :sweat_smile:

If the help would explain the current behaviour correctly, would it still be an issue for you? i.e. can you just check for empty output in your use-case where you need to know about warnings?

nalves599 commented 3 months ago

Hey! Thanks for your reply. It's good enough for me and I understand your point of view.

My only concern is trust in the output to check something (i.e. if it has warnings, some output will be printed) :/

But as you discussed, having the option to say that warnings are errors is the best.

r-vdp commented 1 month ago

I was surprised to notice that my git pre-commit hooks do not complain about warnings. I think it would be nice to make this configurable, like exit with 0 by default when there's only warnings, but accept an option like --fail-on-warnings or such to have nil exit with another error code if desired.

tennox commented 1 month ago

Workaround: ! nil | grep . But yeah..