From d961f94a8b7b6caee11e2fc6a1097823c3ac7e4f Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Fri, 11 Jul 2025 12:59:05 +1000 Subject: [PATCH] Solver: shorten the skipping message if needed Also add a test to prevent this regressing. Closes: https://github.com/haskell/cabal/issues/4251 --- .../src/Distribution/Solver/Modular/Message.hs | 6 +++--- .../UnitTests/Distribution/Solver/Modular/Solver.hs | 13 +++++++++++++ changelog.d/pr-11062 | 8 ++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 changelog.d/pr-11062 diff --git a/cabal-install-solver/src/Distribution/Solver/Modular/Message.hs b/cabal-install-solver/src/Distribution/Solver/Modular/Message.hs index d6ffadf0abf..21e27fe675c 100644 --- a/cabal-install-solver/src/Distribution/Solver/Modular/Message.hs +++ b/cabal-install-solver/src/Distribution/Solver/Modular/Message.hs @@ -282,7 +282,7 @@ showOption qpn@(Q _pp pn) (POption i linkedTo) = -- >>> showOptions foobarQPN [k1, k2] -- "foo-bar; foo-bar~>bazqux.foo-bar-1, foo-bar~>bazqux.foo-bar-2" -- >>> showOptions foobarQPN [v0, i1, k2] --- "foo-bar; 0, 1/installed-inplace, foo-bar~>bazqux.foo-bar-2" +-- "foo-bar; 0, 1/installed-inplace, foo-bar~>bazqux.foo-bar-2 and earlier versions" showOptions :: QPN -> [POption] -> String showOptions _ [] = "unexpected empty list of versions" showOptions q [x] = showOption q x @@ -290,8 +290,8 @@ showOptions q xs = showQPN q ++ "; " ++ (L.intercalate ", " [if isJust linkedTo then showOption q x else showI i -- Don't show the package, just the version - | x@(POption i linkedTo) <- xs - ]) + | x@(POption i linkedTo) <- take 3 xs + ] ++ if length xs >= 3 then " and earlier versions" else "") showGR :: QGoalReason -> String showGR UserGoal = " (user goal)" diff --git a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs index a1f5eed3c62..cb32a33a1e2 100644 --- a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs +++ b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs @@ -964,6 +964,19 @@ tests = skipping = "skipping: A; 2.0.0/installed-2.0.0, 1.0.0/installed-1.0.0" in mkTest db "show skipping versions list, installed" ["B"] $ solverFailure (\msg -> rejecting `isInfixOf` msg && skipping `isInfixOf` msg) + , runTest $ + let db = + [ Right $ exAv "A" 1 [] + , Right $ exAv "A" 2 [] + , Right $ exAv "A" 3 [] + , Right $ exAv "A" 4 [] + , Right $ exAv "A" 5 [] + , Right $ exAv "B" 1 [ExFix "A" 6] + ] + rejecting = "rejecting: A-5.0.0 (conflict: B => A==6.0.0)" + skipping = "skipping: A; 4.0.0, 3.0.0, 2.0.0 and earlier versions (has" + in mkTest db "show summarized skipping versions list" ["B"] $ + solverFailure (\msg -> rejecting `isInfixOf` msg && skipping `isInfixOf` msg) ] ] ] diff --git a/changelog.d/pr-11062 b/changelog.d/pr-11062 new file mode 100644 index 00000000000..50dfa1919f1 --- /dev/null +++ b/changelog.d/pr-11062 @@ -0,0 +1,8 @@ +synopsis: Solver: shorten the skipping message if needed +packages: cabal-install-solver +prs: #11062 + +When the solver fails to find a solution, it can print out a long list +of package versions which failed to meet the requirements. This PR +shortens the message to at most 3 versions which failed to meet the +requriements.