Skip to content

Commit 58bc9c7

Browse files
lf-mergify[bot]
authored andcommitted
TargetSelector: Rewrite the internal error message
This is a mediocre solution, and really should generate a different error entirely at an earlier stage, but I'm not familiar enough with how to achieve that.
1 parent fff7a98 commit 58bc9c7

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

cabal-install/src/Distribution/Client/TargetSelector.hs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -713,21 +713,26 @@ reportTargetSelectorProblems verbosity problems = do
713713
case [ (t, m, ms) | MatchingInternalError t m ms <- problems ] of
714714
[] -> return ()
715715
((target, originalMatch, renderingsAndMatches):_) ->
716-
die' verbosity $ "Internal error in target matching. It should always "
717-
++ "be possible to find a syntax that's sufficiently qualified to "
718-
++ "give an unambiguous match. However when matching '"
719-
++ showTargetString target ++ "' we found "
720-
++ showTargetSelector originalMatch
721-
++ " (" ++ showTargetSelectorKind originalMatch ++ ") which does "
722-
++ "not have an unambiguous syntax. The possible syntax and the "
723-
++ "targets they match are as follows:\n"
716+
die' verbosity $ "Internal error in target matching: could not make an "
717+
++ "unambiguous fully qualified target selector for '"
718+
++ showTargetString target ++ "'.\n"
719+
++ "We made the target '" ++ showTargetSelector originalMatch ++ "' ("
720+
++ showTargetSelectorKind originalMatch ++ ") that was expected to "
721+
++ "be unambiguous but matches the following targets:\n"
724722
++ unlines
725-
[ "'" ++ showTargetString rendering ++ "' which matches "
726-
++ intercalate ", "
723+
[ "'" ++ showTargetString rendering ++ "', matching:"
724+
++ concatMap ("\n - " ++)
727725
[ showTargetSelector match ++
728726
" (" ++ showTargetSelectorKind match ++ ")"
729727
| match <- matches ]
730728
| (rendering, matches) <- renderingsAndMatches ]
729+
++ "\nNote: Cabal expects to be able to make a single fully "
730+
++ "qualified name for a target or provide a more specific error. "
731+
++ "Our failure to do so is a bug in cabal. "
732+
++ "Tracking issue: https://github.com/haskell/cabal/issues/8684"
733+
++ "\n\nHint: this may be caused by trying to build a package that "
734+
++ "exists in the project directory but is missing from "
735+
++ "the 'packages' stanza in your cabal project file."
731736

732737
case [ (t, e, g) | TargetSelectorExpected t e g <- problems ] of
733738
[] -> return ()

0 commit comments

Comments
 (0)