-
Notifications
You must be signed in to change notification settings - Fork 695
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
Track cabal.project provenance for error reporting #3844
Track cabal.project provenance for error reporting #3844
Conversation
@brendanhay, thanks for your PR! By analyzing the annotation information on this pull request, we identified @dcoutts, @hvr and @ezyang to be potential reviewers |
I notice a couple of the |
Great! I think we can probably improve the wording further, especially in the implicit case. In the implicit case we can match on the common kinds of errors and give a specific message. |
Thank you @brendanhay, provenance tracking is a great idea and will help our error messages. You comment that you are not sure the Semigroup/Monoid instances make sense. I think this is indicative of deeper problems with the representation you have chosen. The big problem is that two This also points out that your provenance tracking might be too coarse. When we If we follow this line of reasoning to its logical conclusion, it would seem that we should refactor many of the types in cabal-install to be located, in the same way that GHC associates every Haskell-level expression with a line and column number. That would be a big refactor, but a worthwhile one, in my opinion. But let us not let perfect be the enemy of good. If there's a bad package location, giving the user a list of config files to look at to find the offending one is better than nothing at all. To summarize: EITHER change |
@ezyang Yes, that makes much more sense. I interpret your comment as meaning your long-term preference is to have the location information, In which case one suggestion I have is to implement the |
Yes. I wanted to mention the long term refactor because, as you say, it does supersede the easier version. But in this case the easy fix is pretty easy, so it shouldn't be too bad to throw out later. P.S., the test failure is because provenance isn't preserved if you print out a config, and then read it back in. I'm not sure if this means you should print out the provenance, or just ignore provenance when testing if it was roundtripped. Given the long term plan, probably the latter? |
Both In which case, would it make more sense to use a type such as An alternative would be to track with even more granularity things such as default configuration created via |
In situations like this, I find it is useful to remember that On the other hand, it's fine for the implicit config to come with a provenance. It actually would be quite useful, because the implicit config is NOT used when there's an explicit config. So if there was an error related to implicit config, we could give an appropriate message in that case. |
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 discussion.
} | ||
|
||
setExplicitProjectConfig :: ProjectConfig -> ProjectConfig | ||
setExplicitProjectConfig config = |
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.
Are you sure you don't want to make a helper function for this operation? The helper could be more robust: instead of obliterating the old provenance it would just add to it (unless obliterating it is what you want here? Hard to tell.)
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.
When you say 'helper function' I'm going to assume you mean moving it to the top-level, which since it's not being used elsewhere it's nice (IMO) to have that apparent by its location in a where clause.
The old provenance should indeed be preserved via Set.insert
.
-- | Render bad package location error information for the implicit | ||
-- @cabal.project@ configuration. | ||
-- | ||
-- TODO: This is currently a placeholder with the intention to supply |
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.
OK, well, let's not forget about the todo :)
-- used or if the configuration was read from an explicit file path. | ||
data ProjectConfigProvenance | ||
|
||
-- | The project configuration was implied. |
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.
Implied by what? If I read this, I would have no idea where to look to find out more. Crossref please.
@brendanhay For future reference, participants don't get emails when you push new commits to the branch, you'll have to make a comment to notice it. |
Yeah, was aware my sneaky commits wouldn't be noticed. Still want to add some actual nice errors where the TODO is first. I'll incorporate the other changes you suggested too. |
++ "Please create a package description file <pkgname>.cabal " | ||
++ "or a cabal.project file referencing the packages you " | ||
++ "want to build." | ||
_ -> renderBadPackageLocation bpl |
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.
No cabal.project or cabal file matching the glob './*.cabal' was found.
Please create a package description file <pkgname>.cabal or a cabal.project
file referencing the packages you want to build.
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.
Regarding the other cases, I'm not convinced I actually understand well enough under what situations these errors are raised to correctly word the implicit error message.
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.
Still looking good.
-- per package error. | ||
| otherwise = | ||
"When using configuration(s) from " | ||
++ intercalate ", " (mapMaybe getExplicit provenance) |
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.
Maybe this should also mention if the implicit is used? (I think this case is impossible, so outputting something in that case could help debugging in the future. Or maybe even an error.)
renderImplicitBadPackageLocation :: BadPackageLocation -> String | ||
renderImplicitBadPackageLocation bpl = case bpl of | ||
BadLocGlobEmptyMatch pkglocstr -> | ||
"No cabal.project or cabal file matching the glob '" |
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.
Perhaps say "default glob" rather than "glob"? Because it doesn't actually exist anywhere.
- Excludes provenance from all roundtrip tests - Inserting explicit provenance when read from file - Special cases for bad package errors arising from implicit project configuration
This changes the error when a
cabal.project
is missing from:To (Implicit):
Or (Explicit):
This is done by tracking the provenance of the
cabal.project
file inreadProjectLocalConfig
, otherwise it defaults toImplicit
.The
ProjectConfig
is now also passed toBadPackageLocations
and can be utilised inrenderBadPackageLocation
, although only the provenance is used currently to formulate a title specifying what configuration was used. This will hopefully allow individual calls torenderBadPackageLocation
to be much more informative.Note: I'm not certain the
Semigroup
andMonoid
instances make sense forProjectConfigProvenance
.Fixes #3636