@@ -14,7 +14,6 @@ Types and functions related to Stack's @ghci@ and @repl@ commands.
14
14
module Stack.Ghci
15
15
( GhciOpts (.. )
16
16
, GhciPkgInfo (.. )
17
- , GhciException (.. )
18
17
, GhciPrettyException (.. )
19
18
, ModuleMap
20
19
, ghciCmd
@@ -102,42 +101,15 @@ import Stack.Types.SourceMap
102
101
import System.IO ( putStrLn )
103
102
import System.Permissions ( setScriptPerms )
104
103
105
- -- | Type representing exceptions thrown by functions exported by the
106
- -- "Stack.Ghci" module.
107
- data GhciException
108
- = InvalidPackageOption ! String
109
- | LoadingDuplicateModules
110
- | MissingFileTarget ! String
111
- | Can'tSpecifyFilesAndTargets
112
- | Can'tSpecifyFilesAndMainIs
113
- deriving (Show , Typeable )
114
-
115
- instance Exception GhciException where
116
- displayException (InvalidPackageOption name) =
117
- " Error: [S-6716]\n "
118
- ++ " Failed to parse '--package' option " ++ name ++ " ."
119
- displayException LoadingDuplicateModules = unlines
120
- [ " Error: [S-9632]"
121
- , " Not attempting to start ghci due to these duplicate modules."
122
- , " Use '--no-load' to try to start it anyway, without loading any \
123
- \modules (but these are still likely to cause errors)."
124
- ]
125
- displayException (MissingFileTarget name) =
126
- " Error: [S-3600]\n "
127
- ++ " Cannot find file target " ++ name ++ " ."
128
- displayException Can'tSpecifyFilesAndTargets =
129
- " Error: [S-9906]\n "
130
- ++ " Cannot use 'stack ghci' with both file targets and package targets."
131
- displayException Can'tSpecifyFilesAndMainIs =
132
- " Error: [S-5188]\n "
133
- ++ " Cannot use 'stack ghci' with both file targets and '--main-is' \
134
- \flag."
135
-
136
104
-- | Type representing \'pretty\' exceptions thrown by functions exported by the
137
105
-- "Stack.Ghci" module.
138
106
data GhciPrettyException
139
107
= GhciTargetParseException ! [StyleDoc ]
140
108
| CandidatesIndexOutOfRangeBug
109
+ | InvalidPackageOption ! String
110
+ | FileTargetIsInvalidAbsFile ! String
111
+ | Can'tSpecifyFilesAndTargets
112
+ | Can'tSpecifyFilesAndMainIs
141
113
deriving (Show , Typeable )
142
114
143
115
instance Pretty GhciPrettyException where
@@ -152,6 +124,40 @@ instance Pretty GhciPrettyException where
152
124
]
153
125
pretty CandidatesIndexOutOfRangeBug = bugPrettyReport " [S-1939]" $
154
126
flow " figureOutMainFile: index out of range."
127
+ pretty (InvalidPackageOption name) =
128
+ " [S-6716]"
129
+ <> line
130
+ <> fillSep
131
+ [ flow " Failed to parse"
132
+ , style Shell " --package"
133
+ , " option"
134
+ , style Target (fromString name) <> " ."
135
+ ]
136
+ pretty (FileTargetIsInvalidAbsFile name) =
137
+ " [S-3600]"
138
+ <> line
139
+ <> fillSep
140
+ [ flow " Cannot work out a valid path for file target"
141
+ , style File (fromString name) <> " ."
142
+ ]
143
+ pretty Can'tSpecifyFilesAndTargets =
144
+ " [S-9906]"
145
+ <> line
146
+ <> fillSep
147
+ [ flow " Cannot use"
148
+ , style Shell " stack ghci"
149
+ , flow " with both file targets and package targets."
150
+ ]
151
+ pretty Can'tSpecifyFilesAndMainIs =
152
+ " [S-5188]"
153
+ <> line
154
+ <> fillSep
155
+ [ flow " Cannot use"
156
+ , style Shell " stack ghci"
157
+ , flow " with both file targets and"
158
+ , style Shell " --main-is"
159
+ , " flag."
160
+ ]
155
161
156
162
instance Exception GhciPrettyException
157
163
@@ -237,7 +243,7 @@ ghci opts = do
237
243
(inputTargets, mfileTargets) <- case etargets of
238
244
Right packageTargets -> pure (packageTargets, Nothing )
239
245
Left rawFileTargets -> do
240
- whenJust mainIsTargets $ \ _ -> throwM Can'tSpecifyFilesAndMainIs
246
+ whenJust mainIsTargets $ \ _ -> prettyThrowM Can'tSpecifyFilesAndMainIs
241
247
-- Figure out targets based on filepath targets
242
248
(targetMap, fileInfo, extraFiles) <- findFileTargets locals rawFileTargets
243
249
pure (targetMap, Just (fileInfo, extraFiles))
@@ -305,7 +311,7 @@ preprocessTargets buildOptsCLI sma rawTargets = do
305
311
let fp = T. unpack fp0
306
312
mpath <- forgivingResolveFile' fp
307
313
case mpath of
308
- Nothing -> throwM ( MissingFileTarget fp)
314
+ Nothing -> prettyThrowM ( FileTargetIsInvalidAbsFile fp)
309
315
Just path -> pure path
310
316
pure (Left fileTargets)
311
317
else do
@@ -318,7 +324,7 @@ preprocessTargets buildOptsCLI sma rawTargets = do
318
324
Just (TargetParseException xs) ->
319
325
prettyThrowM $ GhciTargetParseException xs
320
326
_ -> throwM pex
321
- unless (null fileTargetsRaw) $ throwM Can'tSpecifyFilesAndTargets
327
+ unless (null fileTargetsRaw) $ prettyThrowM Can'tSpecifyFilesAndTargets
322
328
pure (Right normalTargets. targets)
323
329
324
330
parseMainIsTargets ::
@@ -472,7 +478,7 @@ checkAdditionalPackages :: MonadThrow m => [String] -> m [PackageName]
472
478
checkAdditionalPackages pkgs = forM pkgs $ \ name -> do
473
479
let mres = (pkgName <$> parsePackageIdentifier name)
474
480
<|> parsePackageNameThrowing name
475
- maybe (throwM $ InvalidPackageOption name) pure mres
481
+ maybe (prettyThrowM $ InvalidPackageOption name) pure mres
476
482
477
483
runGhci ::
478
484
HasEnvConfig env
@@ -1081,14 +1087,14 @@ checkForIssues pkgs =
1081
1087
checkForDuplicateModules :: HasTerm env => [GhciPkgInfo ] -> RIO env ()
1082
1088
checkForDuplicateModules pkgs =
1083
1089
unless (null duplicates) $
1090
+ -- Two or more files with the same module name are treated as a warning
1091
+ -- rather than an error. See:
1092
+ -- https://github.com/commercialhaskell/stack/issues/5407#issuecomment-707339928
1084
1093
prettyWarn $
1085
1094
flow " Multiple files use the same module name:"
1086
1095
<> line
1087
1096
<> bulletedList (map prettyDuplicate duplicates)
1088
1097
<> line
1089
- -- MSS 2020-10-13 Disabling, may remove entirely in the future
1090
- -- See: https://github.com/commercialhaskell/stack/issues/5407#issuecomment-707339928
1091
- -- throwM LoadingDuplicateModules
1092
1098
where
1093
1099
duplicates ::
1094
1100
[(ModuleName , Map (Path Abs File ) (Set (PackageName , NamedComponent )))]
0 commit comments