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

Refactor shared TargetProblem data types into their own module. #6774

Closed

Conversation

m-renaud
Copy link
Collaborator

This adds a new 'ExtensibleTargetProblem e' type which can be used uniformly
across the commands, supporting the most common use case of errors being one of:
'common', 'none enabled', or 'no targets'. In cases where custom target errors
are needed, the base set can be expanded with a custom problem type, and custom
reporting/rendering is supported.


Please include the following checklist in your PR:

  • Patches conform to the coding conventions.
  • Any changes that could be relevant to users have been recorded in the changelog (add file to changelog.d directory).
  • The documentation has been updated, if necessary.

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

-- | The various error conditions that can occur when matching a
-- 'TargetSelector' against 'AvailableTarget's which can be extended
-- with command specific target problems as described by 'e'.
data ExtensibleTargetProblem e
Copy link
Collaborator

@phadej phadej May 10, 2020

Choose a reason for hiding this comment

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

Can TargetProblemCommon and ExtensibleTargetProblem be merged into one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That would be doable, would just require some more code shuffling. One question would be if we want to inline all of the cases of TargetProblemCommon into the top level ExtensibleTargetProblem or if we want to keep the hierarchy as is.

At the least we could move the TargetProblemCommon definition into TargetProblem.hs, I'd prefer to leave the change of flattening the hierarchy (if that's what we decide to do) to a follow-up PR to keep this one as simply extracting the repeated code into one location.

Copy link
Collaborator

@phadej phadej May 10, 2020

Choose a reason for hiding this comment

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

Please shuffle code.

  • TargetProblemCommon is a good name
  • ExtensibleTargetProblem is bad name
    • ExtensibleTargetProblemNoTarget is also bad. First we rename it from TargetProblemNoTarget to then rename back to TargetProblemNoTarget again.

This commit is good start. But I won't merge it. Please at least try TargetProblemCommon extraction as well in follow up commit, not PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See most recent commit, to summarize:

  • Rename ExtensibleTargetProblem -> TargetProblem (and change alias)
  • Shorten data constructor names in TargetProblem
  • Extracts TargetProblemCommon into TargetProblem.hs

PTAL!

Copy link
Collaborator

@phadej phadej left a comment

Choose a reason for hiding this comment

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

Good but not enough. As commented.

This adds a new 'ExtensibleTargetProblem e' type which can be used uniformly
across the commands, supporting the most common use case of errors being one of:
'common', 'none enabled', or 'no targets'. In cases where custom target errors
are needed, the base set can be expanded with a custom problem type, and custom
reporting/rendering is supported.
Also:
- Rename ExtensibleTargetProblem -> TargetProblem
- Rename TargetProblem alias -> TargetProblem' (following convention)
- Shorted data constructor names it TargetProblem
- Moved "problem rendering" to CmdErrorMessages module
@m-renaud m-renaud force-pushed the m-renaud-target-problem-refactor branch from 7d9fe46 to beefecc Compare May 17, 2020 02:07
Copy link
Collaborator

@phadej phadej left a comment

Choose a reason for hiding this comment

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

This looks good. I'll resolve problems after #6818 is merged, and do some minor tweaks.

Thanks!


-- | Target problems that occur during project orchestration.
data TargetProblemCommon
= TargetNotInProject PackageName
Copy link
Collaborator

Choose a reason for hiding this comment

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

3 spaces, cabal is truly diverse!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Haha! I really wish we could just run a formatter over the whole code base (I don't care which one!) so that I can stop worrying about indentation.

@phadej phadej self-assigned this May 18, 2020
@phadej phadej added this to the 3.4.0.0 milestone May 18, 2020
@m-renaud
Copy link
Collaborator Author

Want me to squash commits in the meantime or will you handle that when you make the tweaks and merge later?

@phadej
Copy link
Collaborator

phadej commented May 19, 2020

merged as #6821. Thanks!

@phadej phadej closed this May 19, 2020
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.

None yet

2 participants