Skip to content

Fix #8645: no assertion warning on special modes (help, version, etc.) - #8647

Merged
mergify[bot] merged 3 commits into
masterfrom
issue-8654
Jan 5, 2023
Merged

mergify[bot] merged 3 commits into
masterfrom
issue-8654

Conversation

@andreasabel

@andreasabel andreasabel commented Dec 30, 2022 •

Copy link
Copy Markdown
Member

Fix #8645: no assertion warning on special modes (help, version, etc.); print warning to stderr.

This PR 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.

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.
@andreasabel andreasabel added re: devx Improving the cabal developer experience (internal issue) re: warnings Concerning warnings printed by cabal labels Dec 30, 2022
@andreasabel andreasabel changed the title Fix #8654: no assertion warning on special modes (help, version, etc.) Fix #8645: no assertion warning on special modes (help, version, etc.) Dec 30, 2022
@Mikolaj
Mikolaj requested a review from jneira December 30, 2022 13:23

@Mikolaj Mikolaj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nitpick: the refactoring and the functionality change would ideally be in separate commits.

@SaadAhmedGit

Copy link
Copy Markdown
Contributor

Shouldn't the warning message be:

"Warning: this is a debug build of cabal-install with assertions enabled."

instead of

"this is a debug build of cabal-install with assertions enabled."

Since the string "Warning: " was being prepended to the message automatically with warn which has now been removed thus, requiring the word to be written explicitly in the message. At least, it was that way when it printed to stdout before using warn.

@ulysses4ever

Copy link
Copy Markdown
Collaborator

If the reason for doing away with warn is that -v0 is not parsed yet, maybe warnIfAssertionsAreEnabled could be pushed even further, to the point where -v0 is parsed and the verbosity machinery is up?

@Mikolaj
Mikolaj requested a review from SaadAhmedGit December 30, 2022 17:04
Comment thread cabal-install/main/Main.hs Resolved
@jneira

jneira commented Dec 30, 2022

Copy link
Copy Markdown
Member

Thanks for the fix, it makes sense to not warn on those commands. Some chance of having a test for this?

@Mikolaj

Mikolaj commented Dec 30, 2022

Copy link
Copy Markdown
Member

Ouch, from all this enthusiasm, I forgot to ask for a test and a changelog file.

@andreasabel

Copy link
Copy Markdown
Member Author

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 cabal-install with assertions on? Which test would be a model for the test envisioned here?

Changelog: I think this should not go into the changelog, as it does not affect regular users of Cabal and cabal-install. If I am not mistaken, assertions will be off when building from Hackage...

@Mikolaj

Mikolaj commented Jan 2, 2023 •

Copy link
Copy Markdown
Member

Test: It seems we didn't have a test for this in the first place, otherwise it would have been broken by this PR.

Indeed, that's strange.

What kind of test do you imagine for this? Does CI run on tests on a cabal-install with assertions on?

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 cabal-install binary is called directly (on one of the commands that trigger the warning).

Which test would be a model for the test envisioned here?

There may not be one.

Changelog: I think this should not go into the changelog, as it does not affect regular users of Cabal and cabal-install. If I am not mistaken, assertions will be off when building from Hackage...

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.

@andreasabel

Copy link
Copy Markdown
Member Author

@ulysses4ever :

If the reason for doing away with warn is that -v0 is not parsed yet, maybe warnIfAssertionsAreEnabled could be pushed even further, to the point where -v0 is parsed and the verbosity machinery is up?

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.

@andreasabel

Copy link
Copy Markdown
Member Author

@Mikolaj: Ok, I added a changelog.

PR needs SQUASHING to integrate this into the main commit.

@Mikolaj

Mikolaj commented Jan 2, 2023

Copy link
Copy Markdown
Member

@Mikolaj: Ok, I added a changelog.

Thank you.

PR needs SQUASHING to integrate this into the main commit.

I think, if you set the label already, it will get squashed at the right time (meaning, after reviews and 2 days).

@andreasabel andreasabel added squash+merge me Tell Mergify Bot to squash-merge attention: needs-review labels Jan 2, 2023

@SaadAhmedGit SaadAhmedGit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ulysses4ever

Copy link
Copy Markdown
Collaborator

@andreasabel

It seems pushing this further in would require to prepend it to every command.

But it means, then, that -v0 is handled in every command? I hoped it's not the case. If it is, maybe a refactoring pulling it up would make sense, and that would allow to push the assertion message after it still?

@andreasabel

Copy link
Copy Markdown
Member Author

@ulysses4ever wrote:
But it means, then, that -v0 is handled in every command? I hoped it's not the case. If it is, maybe a refactoring pulling it up would make sense, and that would allow to push the assertion message after it still?

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.

@ulysses4ever

Copy link
Copy Markdown
Collaborator

@andreasabel fair enough!

@jneira

jneira commented Jan 2, 2023

Copy link
Copy Markdown
Member

Test: It seems we didn't have a test for this in the first place, otherwise it would have been broken by this PR.

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
But to be fair if the tested cabal executable has no assertions, it is difficult to add them

@Mikolaj

Mikolaj commented Jan 3, 2023

Copy link
Copy Markdown
Member

if the tested cabal executable has no assertions, it is difficult to add them

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 cabal.project.validate turns up -fno-ignore-asserts. What's your evidence we test without assertions?

@mergify mergify Bot added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Jan 5, 2023
@mergify
mergify Bot merged commit 1f87c0f into master Jan 5, 2023
@andreasabel
andreasabel deleted the issue-8654 branch January 6, 2023 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

attention: needs-review merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days re: devx Improving the cabal developer experience (internal issue) re: warnings Concerning warnings printed by cabal squash+merge me Tell Mergify Bot to squash-merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warning: "debug build with assertions" interferes with --numeric-version

5 participants