Skip to content

cabal check: add typed errors #8269

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

Merged
merged 3 commits into from
Jul 20, 2022
Merged

cabal check: add typed errors #8269

merged 3 commits into from
Jul 20, 2022

Conversation

ffaf1
Copy link
Collaborator

@ffaf1 ffaf1 commented Jul 5, 2022

Towards #8211


Please include the following checklist in your PR:

  • Patches conform to the coding conventions.
  • (no user-relevant change)
  • The documentation has been updated, if necessary.

Please also shortly describe how you tested your change. Bonus points for added tests!

Copy link
Member

@andreasabel andreasabel left a comment

Choose a reason for hiding this comment

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

Good next step (getting away from String errors towards structured errors)!

@ffaf1 ffaf1 force-pushed the typed-errors branch 3 times, most recently from 291a877 to d9d7d12 Compare July 8, 2022 17:57
@ffaf1 ffaf1 force-pushed the typed-errors branch 5 times, most recently from 17bb456 to 44d664b Compare July 18, 2022 12:51
@ffaf1 ffaf1 changed the title cabal check: add typed errors (very WiP) cabal check: add typed errors (WiP) Jul 18, 2022
@ffaf1 ffaf1 force-pushed the typed-errors branch 8 times, most recently from fbc7820 to 8bd81ff Compare July 19, 2022 08:16
@ffaf1 ffaf1 changed the title cabal check: add typed errors (WiP) cabal check: add typed errors Jul 19, 2022
@@ -146,7 +146,7 @@ data PackageDescription
extraTmpFiles :: [FilePath],
extraDocFiles :: [FilePath]
}
deriving (Generic, Show, Read, Eq, Typeable, Data)
deriving (Generic, Show, Read, Eq, Ord, Typeable, Data)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had to add a number of Ord instances after structuring check errors (before: sorting was done on output Strings). It seems to me the new deriving (Ord) will not cause problems (most of the types are sum types).

deriving (Eq, Ord)

instance Show PackageCheck where
show notice = explanation notice
show notice = ppExplanation (explanation notice)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don’t like Show instances that cannot be Read back, but since this is a public interface (used by hackage-server, stack etc.) I did not modify this behaviour.

@@ -1,3 +1,3 @@
# Setup configure
Configuring build-tool-depends-missing-0.1.0.0...
Error: setup: The package depends on a missing internal executable:
Error: setup: The package depends on a missing internal executable: build-tool-depends-missing:hello-world
Copy link
Collaborator Author

@ffaf1 ffaf1 Jul 20, 2022

Choose a reason for hiding this comment

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

Introducing MissingInternalExe highlighted a bug, I corrected it and accepted the new test output.

@@ -1,4 +1,4 @@
# cabal check
Warning: The following errors will cause portability problems on other environments:
Warning: The 'ghc-options' contain the path 'dist/file' which points inside the 'dist' directory. This is not reliable because the location of this directory is configurable by the user (or package manager). In addition the layout of the 'dist' directory is subject to change in future versions of Cabal.
Warning: 'ghc-options' path 'dist/file' points inside the 'dist' directory. This is not reliable because the location of this directory is configurable by the user (or package manager). In addition the layout of the 'dist' directory is subject to change in future versions of Cabal.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Minor rewording due to refactoring two string errors in one data constructor.

Warning: In 'extra-source-files': the pattern 'dir/*.html' does not match any files.
Warning: In 'extra-source-files': the pattern 'dir/*.html' does not match the file 'dir/foo.en.html' because the extensions do not exactly match (e.g., foo.en.html does not exactly match *.html). To enable looser suffix-only matching, set 'cabal-version: 2.4' or higher.
Warning: In 'data-files': the pattern 'non-existent-directory/*.dat' attempts to match files in the directory 'non-existent-directory', but there is no directory by that name.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Output is the same, lines are sorted differently (before: output string sorting).

@ffaf1
Copy link
Collaborator Author

ffaf1 commented Jul 20, 2022

Ready for review, the 112 cabal check tests make me confident that this refactoring is sound.

Meat of the patch is data CheckExplanation and its pretty printing function. Typed errors open new opportunities for refactoring and are more friendly to third party tools.

@ffaf1 ffaf1 marked this pull request as ready for review July 20, 2022 09:15
Copy link
Member

@jneira jneira left a comment

Choose a reason for hiding this comment

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

Looks really good, many thanks

@jneira jneira added the squash+merge me Tell Mergify Bot to squash-merge label Jul 20, 2022
@mergify mergify bot merged commit b7afc97 into haskell:master Jul 20, 2022
@ffaf1 ffaf1 deleted the typed-errors branch July 21, 2022 03:32
@ffaf1 ffaf1 mentioned this pull request Jul 21, 2022
4 tasks
@@ -504,10 +504,10 @@ printPackageProblems verbosity pkg_descr = do
(errors, warnings) = partition isDistError (pureChecks ++ ioChecks)
unless (null errors) $
notice verbosity $ "Distribution quality errors:\n"
++ unlines (map explanation errors)
++ unlines (map show errors)
Copy link
Member

Choose a reason for hiding this comment

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

Isn't introducing show here backwards? The aim should be to reserve show for Haskell representations of data, and use pretty or the like for user-friendly display.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed indeed! I would have removed that Show instance and explanation accessor which is at risk of becoming partial in the future.

I did not do it because the latter that would break hackage-server (they use explanation) and the former (maybe) other packages depending on Cabal (hackage-server? stack? some IDEs? — I cannot be sure about that because hunting shows in the wild is not as easy).

If we collectively decide it is a price worth paying, I will gladly do it! Indeed a Show that cannot be Read back is not haskelly at all!

if null errors
then traverse_ (warn verbosity) warnings
else die' verbosity (intercalate "\n\n" errors)
then traverse_ (warn verbosity) (map show warnings)
Copy link
Member

Choose a reason for hiding this comment

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

See below. Show is for Haskell concrete syntax of data, for displaying to user use pretty.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, reading better, I undestand now: «do not introduce show in internal code». That is very reasonable. I can make a function for principled pretty printing and use it internally, if we decide to deprecate that Show instance later we can do it without rewriting some of the implementation.

Will make a PR this evening or tomorrow.

@ffaf1 ffaf1 linked an issue Feb 12, 2025 that may be closed by this pull request
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reimplement cabal check
4 participants