nil icon indicating copy to clipboard operation
nil copied to clipboard

Wrong return code on nil diagnostics

Open nalves599 opened this issue 1 year ago • 1 comments

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

nalves599 avatar Mar 24 '24 15:03 nalves599

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?

tennox avatar May 07 '24 18:05 tennox

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.

nalves599 avatar May 18 '24 23:05 nalves599

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.

r-vdp avatar Jul 09 '24 13:07 r-vdp

Workaround: ! nil | grep . But yeah..

tennox avatar Jul 09 '24 17:07 tennox