-
Notifications
You must be signed in to change notification settings - Fork 710
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
Conversation
There was a problem hiding this 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)!
291a877
to
d9d7d12
Compare
17bb456
to
44d664b
Compare
cabal check
: add typed errors (very WiP)cabal check
: add typed errors (WiP)
fbc7820
to
8bd81ff
Compare
cabal check
: add typed errors (WiP)cabal check
: add typed errors
@@ -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) |
There was a problem hiding this comment.
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 String
s). 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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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).
Ready for review, the 112 Meat of the patch is |
There was a problem hiding this 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
@@ -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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 show
s 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) |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
Towards #8211
Please include the following checklist in your PR:
Please also shortly describe how you tested your change. Bonus points for added tests!