@@ -37,43 +37,17 @@ import Stack.Types.StackYamlLoc ( StackYamlLoc (..) )
37
37
import System.Console.ANSI ( hSupportsANSIWithoutEmulation )
38
38
import System.Process ( rawSystem , readProcess )
39
39
40
- -- | Type representing exceptions thrown by functions exported by the
40
+ -- | Type representing \'pretty\' exceptions thrown by functions in the
41
41
-- "Stack.Upgrade" module.
42
- data UpgradeException
43
- = NeitherBinaryOrSourceSpecified
42
+ data UpgradePrettyException
43
+ = ResolverOptionInvalid
44
+ | NeitherBinaryOrSourceSpecified
44
45
| ExecutableFailure
45
46
| CommitsNotFound String String
46
47
| StackInPackageIndexNotFound
47
48
| VersionWithNoRevision
48
49
deriving (Show , Typeable )
49
50
50
- instance Exception UpgradeException where
51
- displayException NeitherBinaryOrSourceSpecified =
52
- " Error: [S-3642]\n "
53
- ++ " You must allow either binary or source upgrade paths."
54
- displayException ExecutableFailure =
55
- " Error: [S-8716]\n "
56
- ++ " Non-success exit code from running newly downloaded executable."
57
- displayException (CommitsNotFound branch repo) = concat
58
- [ " Error: [S-7114]\n "
59
- , " No commits found for branch "
60
- , branch
61
- , " on repo "
62
- , repo
63
- ]
64
- displayException StackInPackageIndexNotFound =
65
- " Error: [S-9668]\n "
66
- ++ " No Stack version found in package indices."
67
- displayException VersionWithNoRevision =
68
- " Error: [S-6648]\n "
69
- ++ " Latest version with no revision."
70
-
71
- -- | Type representing \'pretty\' exceptions thrown by functions in the
72
- -- "Stack.Upgrade" module.
73
- data UpgradePrettyException
74
- = ResolverOptionInvalid
75
- deriving (Show , Typeable )
76
-
77
51
instance Pretty UpgradePrettyException where
78
52
pretty ResolverOptionInvalid =
79
53
" [S-8761]"
@@ -85,6 +59,31 @@ instance Pretty UpgradePrettyException where
85
59
, style Shell " upgrade"
86
60
, " command."
87
61
]
62
+ pretty NeitherBinaryOrSourceSpecified =
63
+ " [S-3642]"
64
+ <> line
65
+ <> flow " You must allow either binary or source upgrade paths."
66
+ pretty ExecutableFailure =
67
+ " [S-8716]"
68
+ <> line
69
+ <> flow " Non-success exit code from running newly downloaded executable."
70
+ pretty (CommitsNotFound branch repo) =
71
+ " [S-7114]"
72
+ <> line
73
+ <> fillSep
74
+ [ flow " No commits found for branch"
75
+ , style Current (fromString branch)
76
+ , flow " on repo"
77
+ , style Url (fromString repo) <> " ."
78
+ ]
79
+ pretty StackInPackageIndexNotFound =
80
+ " [S-9668]"
81
+ <> line
82
+ <> flow " No Stack version found in package indices."
83
+ pretty VersionWithNoRevision =
84
+ " [S-6648]"
85
+ <> line
86
+ <> flow " Latest version with no revision."
88
87
89
88
instance Exception UpgradePrettyException
90
89
@@ -130,7 +129,7 @@ upgrade builtHash (UpgradeOpts mbo mso) = case (mbo, mso) of
130
129
-- FIXME It would be far nicer to capture this case in the options parser
131
130
-- itself so we get better error messages, but I can't think of a way to
132
131
-- make it happen.
133
- (Nothing , Nothing ) -> throwIO NeitherBinaryOrSourceSpecified
132
+ (Nothing , Nothing ) -> prettyThrowIO NeitherBinaryOrSourceSpecified
134
133
(Just bo, Nothing ) -> binary bo
135
134
(Nothing , Just so) -> source so
136
135
-- See #2977 - if --git or --git-repo is specified, do source upgrade.
@@ -199,7 +198,7 @@ binaryUpgrade (BinaryOpts mplatform force' mver morg mrepo) =
199
198
\ tmpFile -> do
200
199
-- Sanity check!
201
200
ec <- rawSystem (toFilePath tmpFile) [" --version" ]
202
- unless (ec == ExitSuccess ) (throwIO ExecutableFailure )
201
+ unless (ec == ExitSuccess ) (prettyThrowIO ExecutableFailure )
203
202
204
203
sourceUpgrade ::
205
204
Maybe String
@@ -215,7 +214,7 @@ sourceUpgrade builtHash (SourceOpts gitRepo) =
215
214
[]
216
215
latestCommit <-
217
216
case words remote of
218
- [] -> throwIO $ CommitsNotFound branch repo
217
+ [] -> prettyThrowIO $ CommitsNotFound branch repo
219
218
x: _ -> pure x
220
219
when (isNothing builtHash) $
221
220
prettyWarnS
@@ -225,10 +224,10 @@ sourceUpgrade builtHash (SourceOpts gitRepo) =
225
224
\the contrary."
226
225
if builtHash == Just latestCommit
227
226
then do
228
- prettyInfoS " Already up-to-date, no upgrade required"
227
+ prettyInfoS " Already up-to-date, no upgrade required. "
229
228
pure Nothing
230
229
else do
231
- prettyInfoS " Cloning stack"
230
+ prettyInfoS " Cloning stack. "
232
231
-- NOTE: "--recursive" was added after v1.0.0 (and before the next
233
232
-- release). This means that we can't use submodules in the Stack
234
233
-- repo until we're comfortable with "stack upgrade --git" not
@@ -258,18 +257,18 @@ sourceUpgrade builtHash (SourceOpts gitRepo) =
258
257
Nothing -> withConfig NoReexec $ do
259
258
void
260
259
$ updateHackageIndex
261
- $ Just " Updating index to make sure we find the latest Stack version"
260
+ $ Just " Updating index to make sure we find the latest Stack version. "
262
261
mversion <- getLatestHackageVersion
263
262
YesRequireHackageIndex
264
263
" stack"
265
264
UsePreferredVersions
266
265
(PackageIdentifierRevision _ version _) <-
267
266
case mversion of
268
- Nothing -> throwIO StackInPackageIndexNotFound
267
+ Nothing -> prettyThrowIO StackInPackageIndexNotFound
269
268
Just version -> pure version
270
269
if version <= stackVersion
271
270
then do
272
- prettyInfoS " Already at latest version, no upgrade required"
271
+ prettyInfoS " Already at latest version, no upgrade required. "
273
272
pure Nothing
274
273
else do
275
274
suffix <- parseRelDir $ " stack-" ++ versionString version
@@ -279,7 +278,7 @@ sourceUpgrade builtHash (SourceOpts gitRepo) =
279
278
" stack"
280
279
version
281
280
case mrev of
282
- Nothing -> throwIO VersionWithNoRevision
281
+ Nothing -> prettyThrowIO VersionWithNoRevision
283
282
Just (_rev, cfKey, treeKey) -> do
284
283
let ident = PackageIdentifier " stack" version
285
284
unpackPackageLocation dir $ PLIHackage ident cfKey treeKey
0 commit comments