Skip to content

Cabal Error Refactor#9018

Merged
gbaz merged 33 commits into
haskell:masterfrom
SuganyaAK:Cabal-Error-Refactor
Jul 20, 2023
Merged

Cabal Error Refactor#9018
gbaz merged 33 commits into
haskell:masterfrom
SuganyaAK:Cabal-Error-Refactor

Conversation

@SuganyaAK

@SuganyaAK SuganyaAK commented Jun 12, 2023

Copy link
Copy Markdown
Collaborator

Fixes #8618 #8543


This PR introduces three major changes

  1. A datatype CabalException for the Cabal package that has just enough constructors to cover a few modules I have committed as part of this PR, which will incrementally grow and a future idea of creating CabalInstallException for Cabal-Install Package.
  2. A function dieWithException which will replace die' function and throws Exceptions.
  3. A datatype VerboseException which will be polymorphic over CabalException and CabalInstallException

I would appreciate your feedback, review comments and suggestions.

  1. To identify/differentiate cabal errors, I used "C=" as suggested in issue Integration with the error message index? #8543.
  2. For the start, I used random numbers for error codes. I plan to Index these error codes and document it, I request suggestions or directions on this.

Please include the following checklist in your PR:

Bonus points for added automated tests!

…' calls and throws Error types as exception.

CabalException will hold all ErrorTypes, types will be incrementally added per module.
The VerboseException a will have CabalException and cabalInstallException variously in the a position

Utils.hs
1. Creation of Error data types
2. Diewithexception and exceptionCode function
3. Instance for VerboseException

Bench.hs and install.hs
1. Replaced die' call sites with dieWithException

Right now I have only added errors from two modules Distribtuion/Simple/Bench and Distribution/Simple/Install. Error types will be added incrementally.
@ulysses4ever

Copy link
Copy Markdown
Collaborator

One immediate objection that comes to mind: let's not put more stuff in Utils.hs and instead have a separate Errors module?

@ulysses4ever ulysses4ever added type: enhancement re: error-message Concerning error messages delivered to the user labels Jun 13, 2023
@ulysses4ever
ulysses4ever requested a review from gbaz June 13, 2023 00:18
@ulysses4ever

Copy link
Copy Markdown
Collaborator

More generally, CI runs with -Werror, which means that in order to get a useful feedback from it you should make sure that your code compiles without warnings.

Also, we format the code base with fourmolu-0.12. Install it and run make style to make sure you adhere to its rules...

@SuganyaAK

Copy link
Copy Markdown
Collaborator Author

One immediate objection that comes to mind: let's not put more stuff in Utils.hs and instead have a separate Errors module?

Yes I agree. It will be easy to refer to the exception types as well.
errors.hs or exceptions.hs which will be a better module name u think? and creating in Distribution.Simple will make sense right?

@ulysses4ever

Copy link
Copy Markdown
Collaborator

I don't think the name or location matter all that much: we can always bike-sched it. I'd look what others do (e.g. Stack) or just go with Distribution.Simple.Errors.

@gbaz

gbaz commented Jun 15, 2023

Copy link
Copy Markdown
Collaborator

This is a good start. You'll eventually want a version of withMetadata that gets the callStack from VerboseException passed in -- or to inline that function into the display instance.

Also, I think the idea is that each type of exception gets its own constructor with its own code. So each individual BenchmarkException etc. should have a constructor eventually, rather than one catchall constructor which takes a string. Then there should be a function exceptionToMessage or the like that maps each exception constructor to the rendered string.

@SuganyaAK

Copy link
Copy Markdown
Collaborator Author

This is a good start. You'll eventually want a version of withMetadata that gets the callStack from VerboseException passed in -- or to inline that function into the display instance.

Also, I think the idea is that each type of exception gets its own constructor with its own code. So each individual BenchmarkException etc. should have a constructor eventually, rather than one catchall constructor which takes a string. Then there should be a function exceptionToMessage or the like that maps each exception constructor to the rendered string.

Thank you, I have created a function exceptionWithMetada which takes in the callStack from VerboseException and made a few changes to the code as it already sets AlwaysMark and VerboseTrace.

The new module errors.hs has the constructors for Cabal Exceptions , functions exceptionCode(renders error codes) and exceptionMessage(renders error messages).

On the idea of each type of exception having its own constructor, I have incorporated the same in the modules bench.hs and install.hs.
However in the install.hs module, I have grouped a few dieWithException calls to one constructor CompilerNotInstalled as the errors are similar. Please let me know is this makes sense.

…' calls and throws Error types as exception.

CabalException will hold all ErrorTypes, types will be incrementally added per module.
The VerboseException a will have CabalException and cabalInstallException variously in the a position

Utils.hs
1. Creation of Error data types
2. Diewithexception and exceptionCode function
3. Instance for VerboseException

Bench.hs and install.hs
1. Replaced die' call sites with dieWithException

Right now I have only added errors from two modules Distribtuion/Simple/Bench and Distribution/Simple/Install. Error types will be added incrementally.
@SuganyaAK
SuganyaAK force-pushed the Cabal-Error-Refactor branch from 5663f3b to 9e6a92c Compare June 23, 2023 13:51
Comment thread Cabal/src/Distribution/Simple/Utils.hs
Comment thread Cabal/src/Distribution/Simple/Utils.hs Outdated
Comment thread Cabal/src/Distribution/Simple/Errors.hs Outdated
This file is redundant.
This file is redundant.
Comment thread Cabal/src/Distribution/Simple/Errors.hs Outdated
Comment thread Cabal/src/Distribution/Simple/Utils.hs Outdated
@ulysses4ever

Copy link
Copy Markdown
Collaborator

One more thing: there's a "Manual QA process": https://github.com/haskell/cabal/blob/master/CONTRIBUTING.md#qa-notes It'd be best if in the original post in the PR under the heading "QA Notes" you put instructions on how to create a simple project that fails and prints a message with an error code.

@gbaz

gbaz commented Jul 10, 2023

Copy link
Copy Markdown
Collaborator

The "rip" changes look good, but note the new failures.

Also I think you are printing callstacks at too low a verbosity -- note that there were no callstacks printed in these circumstances before.

@SuganyaAK

Copy link
Copy Markdown
Collaborator Author

The "rip" changes look good, but note the new failures.

Also I think you are printing callstacks at too low a verbosity -- note that there were no callstacks printed in these circumstances before.

I see for all the test cases that are failed in this run, the marked verbose input is "-vverbose +markoutput +nowrap". I think the recent failures that popped up, happened after I replaced the die' call sites with new constructors in the Glob.hs . I could see this with the error code that shows. ` Unfortunately all these tests passed on my local, so I couldn't see this coming.

@gbaz

gbaz commented Jul 14, 2023

Copy link
Copy Markdown
Collaborator

I believe this is basically ready for review, and it would be good to rapidly review and merge so that other work can proceed along the same lines on top of this basic exception/reporting structure...

@ulysses4ever
ulysses4ever marked this pull request as ready for review July 14, 2023 15:25
where
notFound module_ = die' verbosity $ "can't find source for module " ++ prettyShow module_
notFound module_ =
dieWithException verbosity $ CantFindSoureModule module_

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

OOC, why is it spelled "Soure" instead of "Source"?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's a typo?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
dieWithException verbosity $ CantFindSoureModule module_
dieWithException verbosity $ CantFindSourceModule module_

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes it was a typo, Thanks for pointing out. Changed to "CantFindSourceModule"

@Kleidukos Kleidukos 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.

Nicely packed first PR for an ambitious goal, thank you very much @SuganyaAK

Comment thread Cabal/src/Distribution/Simple/Errors.hs Outdated
Comment thread Cabal/src/Distribution/Simple/Errors.hs Outdated
Comment thread Cabal/src/Distribution/Simple/Utils.hs Outdated
@SuganyaAK

Copy link
Copy Markdown
Collaborator Author

Nicely packed first PR for an ambitious goal, thank you very much @SuganyaAK

Thank you

Nicely packed first PR for an ambitious goal, thank you very much @SuganyaAK

Thank you @Kleidukos

@SuganyaAK
SuganyaAK requested a review from Kleidukos July 17, 2023 17:45

@Kleidukos Kleidukos 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.

LGTM, thanks!

@gbaz gbaz added squash+merge me Tell Mergify Bot to squash-merge and removed attention: needs-review labels Jul 18, 2023
@mergify mergify Bot added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Jul 20, 2023
@ulysses4ever

Copy link
Copy Markdown
Collaborator

@mergify refresh

@mergify

mergify Bot commented Jul 20, 2023

Copy link
Copy Markdown
Contributor

refresh

✅ Pull request refreshed

@gbaz
gbaz merged commit 667be46 into haskell:master Jul 20, 2023
@SuganyaAK
SuganyaAK deleted the Cabal-Error-Refactor branch August 3, 2023 02:31
@SuganyaAK SuganyaAK mentioned this pull request Aug 7, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days re: error-message Concerning error messages delivered to the user squash+merge me Tell Mergify Bot to squash-merge type: enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Structured Errors infrastructure

5 participants