Skip to content

Commit f75549f

Browse files
authored
Merge pull request #6392 from commercialhaskell/s-1852
Re #6379 Prettier S-6362
2 parents 0c52267 + be579d4 commit f75549f

File tree

7 files changed

+95
-62
lines changed

7 files changed

+95
-62
lines changed

doc/maintainers/stack_errors.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
In connection with considering Stack's support of the
66
[Haskell Error Index](https://errors.haskell.org/) initiative, this page seeks
77
to take stock of the errors that Stack itself can raise, by reference to the
8-
`master` branch of the Stack repository. Last updated: 2023-10-21.
8+
`master` branch of the Stack repository. Last updated: 2023-12-24.
99

1010
* `Stack.main`: catches exceptions from action `commandLineHandler`.
1111

@@ -350,7 +350,6 @@ to take stock of the errors that Stack itself can raise, by reference to the
350350

351351
~~~haskell
352352
[S-7178] = Couldn'tFindPkgId PackageName
353-
[S-6362] | CompilerVersionMismatch (Maybe (ActualCompiler, Arch)) (WantedCompiler, Arch) GHCVariant CompilerBuild VersionCheck (Maybe (Path Abs File)) Text
354353
[S-3127] | Couldn'tParseTargets [Text]
355354
[S-2154] | UnknownTargets (Set PackageName) (Map PackageName Version) (Path Abs File)
356355
[S-1995] | TestSuiteFailure PackageIdentifier (Map Text (Maybe ExitCode)) (Maybe (Path Abs File)) ByteString
@@ -384,6 +383,7 @@ to take stock of the errors that Stack itself can raise, by reference to the
384383
[S-8664] | InvalidFlagSpecification (Set UnusedFlags)
385384
[S-8100] | GHCProfOptionInvalid
386385
[S-1727] | NotOnlyLocal [PackageName] [Text]
386+
[S-6362] | CompilerVersionMismatch (Maybe (ActualCompiler, Arch)) (WantedCompiler, Arch) GHCVariant CompilerBuild VersionCheck (Maybe (Path Abs File)) Text
387387
~~~
388388

389389
- `Stack.Types.Compiler.CompilerException`

package.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ dependencies:
111111
- project-template
112112
- random
113113
- rio >= 0.1.22.0
114-
- rio-prettyprint >= 0.1.7.0
114+
- rio-prettyprint >= 0.1.8.0
115115
- split
116116
- stm
117117
- tar

src/Stack/Setup.hs

+34-19
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ import Stack.Setup.Installed
117117
import Stack.SourceMap
118118
( actualFromGhc, globalsFromDump, pruneGlobals )
119119
import Stack.Storage.User ( loadCompilerPaths, saveCompilerPaths )
120-
import Stack.Types.Build.Exception ( BuildException (..) )
120+
import Stack.Types.Build.Exception ( BuildPrettyException (..) )
121121
import Stack.Types.BuildConfig
122122
( BuildConfig (..), HasBuildConfig (..), projectRootL
123123
, wantedCompilerVersionL
@@ -316,9 +316,9 @@ instance Pretty SetupPrettyException where
316316
<> fillSep
317317
[ flow "Stack does not know how to install GHC for the combination of \
318318
\operating system"
319-
, fromString $ show os
319+
, style Shell (pretty os)
320320
, "and architecture"
321-
, fromString $ show arch <> "."
321+
, style Shell (pretty arch) <> "."
322322
, flow "Please install manually."
323323
]
324324
pretty (MissingDependencies tools) =
@@ -549,14 +549,14 @@ instance Pretty SetupPrettyException where
549549
<> line
550550
<> fillSep
551551
[ flow "Binary upgrade not yet supported on OS:"
552-
, fromString (show os) <> "."
552+
, pretty os <> "."
553553
]
554554
pretty (BinaryUpgradeOnArchUnsupported arch) =
555555
"[S-3249]"
556556
<> line
557557
<> fillSep
558558
[ flow "Binary upgrade not yet supported on architecture:"
559-
, fromString (show arch) <> "."
559+
, pretty arch <> "."
560560
]
561561
pretty (ExistingMSYS2NotDeleted destDir e) =
562562
"[S-4230]"
@@ -605,7 +605,7 @@ data SetupOpts = SetupOpts
605605
-- ^ Don't check for a compatible GHC version/architecture
606606
, soptsSkipMsys :: !Bool
607607
-- ^ Do not use a custom msys installation on Windows
608-
, soptsResolveMissingGHC :: !(Maybe Text)
608+
, soptsResolveMissingGHC :: !(Maybe StyleDoc)
609609
-- ^ Message shown to user for how to resolve the missing GHC
610610
, soptsGHCBindistURL :: !(Maybe String)
611611
-- ^ Alternate GHC binary distribution (requires custom GHCVariant)
@@ -617,7 +617,8 @@ data SetupOpts = SetupOpts
617617
setupEnv ::
618618
NeedTargets
619619
-> BuildOptsCLI
620-
-> Maybe Text -- ^ Message to give user when necessary GHC is not available
620+
-> Maybe StyleDoc
621+
-- ^ Message to give user when necessary GHC is not available.
621622
-> RIO BuildConfig EnvConfig
622623
setupEnv needTargets boptsCLI mResolveMissingGHC = do
623624
config <- view configL
@@ -1143,17 +1144,28 @@ installGhcBindist sopts getSetupInfo' installed = do
11431144
(soptsCompilerCheck sopts)
11441145
(soptsGHCBindistURL sopts)
11451146
| otherwise -> do
1146-
let suggestion = fromMaybe
1147-
(mconcat
1148-
[ "To install the correct GHC into "
1149-
, T.pack (toFilePath (configLocalPrograms config))
1150-
, ", try running 'stack setup' or use the '--install-ghc' flag."
1151-
, " To use your system GHC installation, run \
1152-
\'stack config set system-ghc --global true', \
1153-
\or use the '--system-ghc' flag."
1154-
])
1155-
(soptsResolveMissingGHC sopts)
1156-
throwM $ CompilerVersionMismatch
1147+
let suggestion =
1148+
fromMaybe defaultSuggestion (soptsResolveMissingGHC sopts)
1149+
defaultSuggestion = fillSep
1150+
[ flow "To install the correct version of GHC into the \
1151+
\subdirectory for the specified platform in Stack's \
1152+
\directory for local tools"
1153+
, parens (pretty $ configLocalPrograms config) <> ","
1154+
, flow "try running"
1155+
, style Shell (flow "stack setup")
1156+
, flow "or use the"
1157+
, style Shell "--install-ghc"
1158+
, flow "flag. To use your system GHC installation, run"
1159+
, style
1160+
Shell
1161+
(flow "stack config set system-ghc --global true")
1162+
<> ","
1163+
, flow "or use the"
1164+
, style Shell "--system-ghc"
1165+
, "flag."
1166+
]
1167+
1168+
prettyThrowM $ CompilerVersionMismatch
11571169
Nothing -- FIXME ((\(x, y, _) -> (x, y)) <$> msystem)
11581170
(soptsWantedCompiler sopts, expectedArch)
11591171
ghcVariant
@@ -2065,7 +2077,10 @@ getGhcKey ghcBuild = do
20652077
<> T.pack (ghcVariantSuffix ghcVariant)
20662078
<> T.pack (compilerBuildSuffix ghcBuild)
20672079

2068-
getOSKey :: (MonadThrow m) => Platform -> m Text
2080+
getOSKey ::
2081+
(MonadThrow m)
2082+
=> Platform
2083+
-> m Text
20692084
getOSKey platform =
20702085
case platform of
20712086
Platform I386 Cabal.Linux -> pure "linux32"

src/Stack/Types/Build/Exception.hs

+45-36
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ import Stack.Types.Version ( VersionCheck (..), VersionRange )
4545
-- names beginning @Stack.Build@.
4646
data BuildException
4747
= Couldn'tFindPkgId PackageName
48-
| CompilerVersionMismatch
49-
(Maybe (ActualCompiler, Arch)) -- found
50-
(WantedCompiler, Arch) -- expected
51-
GHCVariant -- expected
52-
CompilerBuild -- expected
53-
VersionCheck
54-
(Maybe (Path Abs File)) -- Path to the stack.yaml file
55-
Text -- recommended resolution
5648
| Couldn'tParseTargets [Text]
5749
| UnknownTargets
5850
(Set PackageName) -- no known version
@@ -93,34 +85,6 @@ instance Exception BuildException where
9385
, packageNameString name
9486
, ")."
9587
]
96-
displayException (CompilerVersionMismatch mactual (expected, eArch) ghcVariant ghcBuild check mstack resolution) = concat
97-
[ "Error: [S-6362]\n"
98-
, case mactual of
99-
Nothing -> "No compiler found, expected "
100-
Just (actual, arch) -> concat
101-
[ "Compiler version mismatched, found "
102-
, compilerVersionString actual
103-
, " ("
104-
, C.display arch
105-
, ")"
106-
, ", but expected "
107-
]
108-
, case check of
109-
MatchMinor -> "minor version match with "
110-
MatchExact -> "exact version "
111-
NewerMinor -> "minor version match or newer with "
112-
, T.unpack $ utf8BuilderToText $ display expected
113-
, " ("
114-
, C.display eArch
115-
, ghcVariantSuffix ghcVariant
116-
, compilerBuildSuffix ghcBuild
117-
, ") (based on "
118-
, case mstack of
119-
Nothing -> "command line arguments"
120-
Just stack -> "resolver setting in " ++ toFilePath stack
121-
, ").\n"
122-
, T.unpack resolution
123-
]
12488
displayException (Couldn'tParseTargets targets) = unlines
12589
$ "Error: [S-3127]"
12690
: "The following targets could not be parsed as package names or \
@@ -286,6 +250,14 @@ data BuildPrettyException
286250
| InvalidFlagSpecification (Set UnusedFlags)
287251
| GHCProfOptionInvalid
288252
| NotOnlyLocal [PackageName] [Text]
253+
| CompilerVersionMismatch
254+
(Maybe (ActualCompiler, Arch)) -- found
255+
(WantedCompiler, Arch) -- expected
256+
GHCVariant -- expected
257+
CompilerBuild -- expected
258+
VersionCheck
259+
(Maybe (Path Abs File)) -- Path to the stack.yaml file
260+
StyleDoc -- recommended resolution
289261
deriving (Show, Typeable)
290262

291263
instance Pretty BuildPrettyException where
@@ -417,6 +389,43 @@ instance Pretty BuildPrettyException where
417389
(map (fromString . T.unpack) exes :: [StyleDoc])
418390
)
419391
<> line
392+
pretty (CompilerVersionMismatch mactual (expected, eArch) ghcVariant ghcBuild check mstack resolution) =
393+
"[S-6362]"
394+
<> line
395+
<> fillSep
396+
[ case mactual of
397+
Nothing -> flow "No compiler found, expected"
398+
Just (actual, arch) -> fillSep
399+
[ flow "Compiler version mismatched, found"
400+
, fromString $ compilerVersionString actual
401+
, parens (pretty arch) <> ","
402+
, flow "but expected"
403+
]
404+
, case check of
405+
MatchMinor -> flow "minor version match with"
406+
MatchExact -> flow "exact version"
407+
NewerMinor -> flow "minor version match or newer with"
408+
, fromString $ T.unpack $ utf8BuilderToText $ display expected
409+
, parens $ mconcat
410+
[ pretty eArch
411+
, fromString $ ghcVariantSuffix ghcVariant
412+
, fromString $ compilerBuildSuffix ghcBuild
413+
]
414+
, parens
415+
( fillSep
416+
[ flow "based on"
417+
, case mstack of
418+
Nothing -> flow "command line arguments"
419+
Just stack -> fillSep
420+
[ flow "resolver setting in"
421+
, pretty stack
422+
]
423+
]
424+
)
425+
<> "."
426+
]
427+
<> blankLine
428+
<> resolution
420429

421430
instance Exception BuildPrettyException
422431

stack.cabal

+4-4
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ library
396396
, project-template
397397
, random
398398
, rio >=0.1.22.0
399-
, rio-prettyprint >=0.1.7.0
399+
, rio-prettyprint >=0.1.8.0
400400
, split
401401
, stm
402402
, tar
@@ -518,7 +518,7 @@ executable stack
518518
, project-template
519519
, random
520520
, rio >=0.1.22.0
521-
, rio-prettyprint >=0.1.7.0
521+
, rio-prettyprint >=0.1.8.0
522522
, split
523523
, stack
524524
, stm
@@ -621,7 +621,7 @@ executable stack-integration-test
621621
, project-template
622622
, random
623623
, rio >=0.1.22.0
624-
, rio-prettyprint >=0.1.7.0
624+
, rio-prettyprint >=0.1.8.0
625625
, split
626626
, stm
627627
, tar
@@ -738,7 +738,7 @@ test-suite stack-unit-test
738738
, random
739739
, raw-strings-qq
740740
, rio >=0.1.22.0
741-
, rio-prettyprint >=0.1.7.0
741+
, rio-prettyprint >=0.1.8.0
742742
, split
743743
, stack
744744
, stm

stack.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ extra-deps:
66
- Cabal-3.10.1.0@sha256:6d11adf7847d9734e7b02785ff831b5a0d11536bfbcefd6634b2b08411c63c94,12316
77
# GHC 9.6.3 comes with process-1.6.17.0, which can segfault on macOS.
88
- process-1.6.18.0@sha256:cd0a3e0376b5a8525983d3131a31e52f9ffefc278ce635eec45a9d3987b8be3e,3025
9+
# lts-22.0 specifies rio-prettyprint-0.1.7.0:
10+
- rio-prettyprint-0.1.8.0@sha256:28a034bfa2842043d4603800e47943027677746cca0b3b8088aee10168870105,1428
911

1012
docker:
1113
enable: false

stack.yaml.lock

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ packages:
1818
size: 1675
1919
original:
2020
hackage: process-1.6.18.0@sha256:cd0a3e0376b5a8525983d3131a31e52f9ffefc278ce635eec45a9d3987b8be3e,3025
21+
- completed:
22+
hackage: rio-prettyprint-0.1.8.0@sha256:28a034bfa2842043d4603800e47943027677746cca0b3b8088aee10168870105,1428
23+
pantry-tree:
24+
sha256: 69850784d99d1c44e85f934433abafad729f87fdc40d375c590c8d4a1cb2886d
25+
size: 779
26+
original:
27+
hackage: rio-prettyprint-0.1.8.0@sha256:28a034bfa2842043d4603800e47943027677746cca0b3b8088aee10168870105,1428
2128
snapshots:
2229
- completed:
2330
sha256: e176944bc843f740e05242fa7a66ca1f440c127e425254f7f1257f9b19add23f

0 commit comments

Comments
 (0)