Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cabal Error Refactor #9018

Merged
merged 33 commits into from
Jul 20, 2023
Merged

Cabal Error Refactor #9018

merged 33 commits into from
Jul 20, 2023

Conversation

SuganyaAK
Copy link
Collaborator

@SuganyaAK SuganyaAK commented Jun 12, 2023

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
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
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
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
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
Copy link
Collaborator

gbaz commented Jun 15, 2023

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
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.
This file is redundant.
This file is redundant.
@ulysses4ever
Copy link
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
Copy link
Collaborator

gbaz commented Jul 10, 2023

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
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
Copy link
Collaborator

gbaz commented Jul 14, 2023

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
@@ -192,7 +192,8 @@ getSourceFiles verbosity dirs modules = flip traverse modules $ \m ->
findFileWithExtension ["hs", "lhs", "hsig", "lhsig"] dirs (ModuleName.toFilePath m)
>>= maybe (notFound m) (return . normalise)
where
notFound module_ = die' verbosity $ "can't find source for module " ++ prettyShow module_
notFound module_ =
dieWithException verbosity $ CantFindSoureModule module_
Copy link
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
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
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
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"

Copy link
Member

@Kleidukos Kleidukos left a comment

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

Cabal/src/Distribution/Simple/Errors.hs Outdated Show resolved Hide resolved
Cabal/src/Distribution/Simple/Errors.hs Outdated Show resolved Hide resolved
Cabal/src/Distribution/Simple/Utils.hs Outdated Show resolved Hide resolved
@SuganyaAK
Copy link
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
Copy link
Member

@Kleidukos Kleidukos left a comment

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
Collaborator

@mergify refresh

@mergify
Copy link
Contributor

mergify bot commented Jul 20, 2023

refresh

✅ Pull request refreshed

@gbaz gbaz merged commit 667be46 into haskell:master Jul 20, 2023
42 of 44 checks passed
@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