Repository navigation
Fix #8645: no assertion warning on special modes (help, version, etc.) - #8647
Conversation
This patch moves the `warnIfAssertionsAreEnabled` until after the main command line argument parsing, and then only prints it on regular operation, i.e. not when just the help or version of cabal was demanded, or the command line could not be parsed. Further, the warning is printed on stderr. The previous attempt to use `warn` does not work as expected, as the verbosity aperatshnik isn't in place yet, so the warning cannot be suppressed by -v0. Drive-by-shooting: straighten the convoluted control flow involving `maybeScriptAndArgs`. This IO computation was invoked "brutto" before, when it is actually only needed in *one* branch of the case distinction.
Mikolaj
left a comment
There was a problem hiding this comment.
A nitpick: the refactoring and the functionality change would ideally be in separate commits.
|
Shouldn't the warning message be:
instead of
Since the string "Warning: " was being prepended to the message automatically with |
|
If the reason for doing away with |
|
Thanks for the fix, it makes sense to not warn on those commands. Some chance of having a test for this? |
|
Ouch, from all this enthusiasm, I forgot to ask for a test and a changelog file. |
Test: It seems we didn't have a test for this in the first place, otherwise it would have been broken by this PR. What kind of test do you imagine for this? Does CI run on tests on a Changelog: I think this should not go into the changelog, as it does not affect regular users of |
Indeed, that's strange.
CI definitely should run only with assertions on. But perhaps it calls cabal-install commands via some internal API bypassing the warning printout? I think we should have at least one test where the
There may not be one.
Yes, assertions are off on Hackage. This is debatable (changelog is useful for all consumers of cabal, including devs and bug reporters, the latter of which get confused most easily by the failed asssertions when reproducing with master branch artifacts from GHA), but I won't insist. |
It seems pushing this further in would require to prepend it to every command. I only pushed it as far in so that it is still before we branch into the individual commands. |
|
@Mikolaj: Ok, I added a changelog. PR needs SQUASHING to integrate this into the main commit. |
Thank you.
I think, if you set the label already, it will get squashed at the right time (meaning, after reviews and 2 days). |
But it means, then, that |
Artem, please have a look at https://github.com/haskell/cabal/blob/7babda92df9e005185e7c9d5e9308a8a96092d7c/cabal-install/main/Main.hs and observe the amount of code duplication there. I think refactoring this is a noble goal, but too much to require for this modest PR. |
|
@andreasabel fair enough! |
That is just the core of the problem (a general problem in the cabal codebase) and no a valid argument to no add them imho |
I think we might have had this discussion long ago, but I don't remember the conclusions. Naively, I'd think we should only ever test binaries with assertions. Perhaps one odd test without assertions to make sure no functional code got inserted into an assertion by mistake. And indeed a quick look at |
Fix #8645: no assertion warning on special modes (help, version, etc.); print warning to
stderr.This PR moves the
warnIfAssertionsAreEnableduntil after the main command line argument parsing, and then only prints it on regular operation, i.e. not when just the help or version of cabal was demanded, or the command line could not be parsed.Further, the warning is printed on stderr. The previous attempt to use
warndoes not work as expected, as the verbosity aperatshnik isn't in place yet, so the warning cannot be suppressed by -v0.Drive-by-shooting: straighten the convoluted control flow involving
maybeScriptAndArgs. This IO computation was invoked "brutto" before, when it is actually only needed in one branch of the case distinction.