Skip to content

Commit c6b32cc

Browse files
authored
Merge pull request commercialhaskell#5957 from commercialhaskell/fix5956
Fix commercialhaskell#5956 Use `displayException`, not `show`
2 parents 79866bb + 76a42da commit c6b32cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+335
-416
lines changed

src/Control/Concurrent/Execute.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ import qualified Data.Set as Set
2222
-- "Control.Concurrent.Execute" module.
2323
data ExecuteException
2424
= InconsistentDependenciesBug
25-
deriving Typeable
25+
deriving (Show, Typeable)
2626

27-
instance Show ExecuteException where
28-
show InconsistentDependenciesBug = bugReport "[S-2816]"
27+
instance Exception ExecuteException where
28+
displayException InconsistentDependenciesBug = bugReport "[S-2816]"
2929
"Inconsistent dependencies were discovered while executing your build \
3030
\plan."
3131

32-
instance Exception ExecuteException
33-
3432
data ActionType
3533
= ATBuild
3634
-- ^ Action for building a package's library and executables. If

src/Options/Applicative/Builder/Extra.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,15 @@ import System.FilePath (takeBaseName, (</>), splitFileName, isRelative, takeExte
5050
-- "Options.Applicative.Builder.Extra" module.
5151
data OptionsApplicativeExtraException
5252
= FlagNotFoundBug
53-
deriving Typeable
53+
deriving (Show, Typeable)
5454

55-
instance Show OptionsApplicativeExtraException where
56-
show FlagNotFoundBug =
55+
instance Exception OptionsApplicativeExtraException where
56+
displayException FlagNotFoundBug =
5757
"Error: [S-2797]\n"
5858
++ "The impossible happened! No valid flags found in \
5959
\enableDisableFlagsNoDefault. Please report this bug at Stack's \
6060
\repository."
6161

62-
instance Exception OptionsApplicativeExtraException
63-
6462
-- | Enable/disable flags for a 'Bool'.
6563
boolFlags :: Bool -- ^ Default value
6664
-> String -- ^ Flag name

src/Stack/Build.hs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ import System.Terminal (fixCodePage)
5454
data CabalVersionException
5555
= AllowNewerNotSupported Version
5656
| CabalVersionNotSupported Version
57-
deriving (Typeable)
57+
deriving (Show, Typeable)
5858

59-
instance Show CabalVersionException where
60-
show (AllowNewerNotSupported cabalVer) = concat
59+
instance Exception CabalVersionException where
60+
displayException (AllowNewerNotSupported cabalVer) = concat
6161
[ "Error: [S-8503]\n"
6262
, "'--allow-newer' requires Cabal version 1.22 or greater, but "
6363
, "version "
6464
, versionString cabalVer
6565
, " was found."
6666
]
67-
show (CabalVersionNotSupported cabalVer) = concat
67+
displayException (CabalVersionNotSupported cabalVer) = concat
6868
[ "Error: [S-5973]\n"
6969
, "Stack no longer supports Cabal versions before 1.19.2, "
7070
, "but version "
@@ -73,25 +73,23 @@ instance Show CabalVersionException where
7373
, "or later or to nightly-2015-05-05 or later."
7474
]
7575

76-
instance Exception CabalVersionException
77-
7876
data QueryException
7977
= SelectorNotFound [Text]
8078
| IndexOutOfRange [Text]
8179
| NoNumericSelector [Text]
8280
| CannotApplySelector Value [Text]
83-
deriving (Typeable)
84-
85-
instance Show QueryException where
86-
show (SelectorNotFound sels) = err "[S-4419]" "Selector not found" sels
87-
show (IndexOutOfRange sels) = err "[S-8422]" "Index out of range" sels
88-
show (NoNumericSelector sels) =
81+
deriving (Show, Typeable)
82+
83+
instance Exception QueryException where
84+
displayException (SelectorNotFound sels) =
85+
err "[S-4419]" "Selector not found" sels
86+
displayException (IndexOutOfRange sels) =
87+
err "[S-8422]" "Index out of range" sels
88+
displayException (NoNumericSelector sels) =
8989
err "[S-4360]" "Encountered array and needed numeric selector" sels
90-
show (CannotApplySelector value sels) =
90+
displayException (CannotApplySelector value sels) =
9191
err "[S-1711]" ("Cannot apply selector to " ++ show value) sels
9292

93-
instance Exception QueryException
94-
9593
-- | Helper function for 'QueryException' instance of 'Show'
9694
err :: String -> String -> [Text] -> String
9795
err msg code sels = "Error: " ++ code ++ "\n" ++ msg ++ ": " ++ show sels

src/Stack/Build/ConstructPlan.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,12 @@ errorOnSnapshot plan@(Plan tasks _finals _unregister installExes) = do
272272
NotOnlyLocal snapTasks snapExes
273273
pure plan
274274

275-
data NotOnlyLocal = NotOnlyLocal [PackageName] [Text]
275+
data NotOnlyLocal
276+
= NotOnlyLocal [PackageName] [Text]
277+
deriving (Show, Typeable)
276278

277-
instance Show NotOnlyLocal where
278-
show (NotOnlyLocal packages exes) = concat
279+
instance Exception NotOnlyLocal where
280+
displayException (NotOnlyLocal packages exes) = concat
279281
[ "Error: [S-1727]\n"
280282
, "Specified only-locals, but I need to build snapshot contents:\n"
281283
, if null packages then "" else concat
@@ -289,7 +291,6 @@ instance Show NotOnlyLocal where
289291
, "\n"
290292
]
291293
]
292-
instance Exception NotOnlyLocal
293294

294295
-- | State to be maintained during the calculation of local packages
295296
-- to unregister.

src/Stack/Build/Execute.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,9 @@ singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} installedMap
17171717
eres <- try $ cabal KeepTHLoading ["copy"]
17181718
case eres of
17191719
Left err@CabalExitedUnsuccessfully{} ->
1720-
throwM $ CabalCopyFailed (packageBuildType package == C.Simple) (show err)
1720+
throwM $ CabalCopyFailed
1721+
(packageBuildType package == C.Simple)
1722+
(displayException err)
17211723
_ -> pure ()
17221724
when hasLibrary $ cabal KeepTHLoading ["register"]
17231725

src/Stack/BuildPlan.hs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ data BuildPlanException
5656
| SnapshotNotFound SnapName
5757
| NeitherCompilerOrResolverSpecified T.Text
5858
| DuplicatePackagesBug
59-
deriving Typeable
59+
deriving (Show, Typeable)
6060

61-
instance Show BuildPlanException where
62-
show (SnapshotNotFound snapName) = unlines
61+
instance Exception BuildPlanException where
62+
displayException (SnapshotNotFound snapName) = unlines
6363
[ "Error: [S-2045]"
6464
, "SnapshotNotFound " ++ snapName'
6565
, "Non existing resolver: " ++ snapName' ++ "."
6666
, "For a complete list of available snapshots see https://www.stackage.org/snapshots"
6767
]
68-
where snapName' = show snapName
69-
show (UnknownPackages stackYaml unknown shadowed) =
68+
where snapName' = show snapName
69+
displayException (UnknownPackages stackYaml unknown shadowed) =
7070
"Error: [S-7571]\n"
7171
++ unlines (unknown' ++ shadowed')
7272
where
@@ -134,17 +134,15 @@ instance Show BuildPlanException where
134134
$ Set.toList
135135
$ Set.unions
136136
$ Map.elems shadowed
137-
show (NeitherCompilerOrResolverSpecified url) = concat
137+
displayException (NeitherCompilerOrResolverSpecified url) = concat
138138
[ "Error: [S-8559]\n"
139139
, "Failed to load custom snapshot at "
140140
, T.unpack url
141141
, ", because no 'compiler' or 'resolver' is specified."
142142
]
143-
show DuplicatePackagesBug = bugReport "[S-5743]"
143+
displayException DuplicatePackagesBug = bugReport "[S-5743]"
144144
"Duplicate packages are not expected here."
145145

146-
instance Exception BuildPlanException
147-
148146
gpdPackages :: [GenericPackageDescription] -> Map PackageName Version
149147
gpdPackages = Map.fromList . map (toPair . C.package . C.packageDescription)
150148
where

src/Stack/Clean.hs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,23 @@ import Stack.Types.SourceMap
2525
data CleanException
2626
= NonLocalPackages [PackageName]
2727
| DeletionFailures [(Path Abs Dir, SomeException)]
28-
deriving Typeable
28+
deriving (Show, Typeable)
2929

30-
instance Show CleanException where
31-
show (NonLocalPackages pkgs) = concat
30+
instance Exception CleanException where
31+
displayException (NonLocalPackages pkgs) = concat
3232
[ "Error: [S-9463]\n"
3333
, "The following packages are not part of this project: "
3434
, intercalate ", " (map show pkgs)
3535
]
36-
show (DeletionFailures failures) = concat
36+
displayException (DeletionFailures failures) = concat
3737
[ "Error: [S-6321]\n"
3838
, "Exception while recursively deleting:\n"
39-
, concatMap (\(dir, e) -> toFilePath dir <> "\n" <> show e <> "\n") failures
39+
, concatMap (\(dir, e) ->
40+
toFilePath dir <> "\n" <> displayException e <> "\n") failures
4041
, "Perhaps you do not have permission to delete these files or they \
4142
\are in use?"
4243
]
4344

44-
instance Exception CleanException
45-
4645
-- | Deletes build artifacts in the current project.
4746
clean :: CleanOpts -> RIO Config ()
4847
clean cleanOpts = do

src/Stack/ComponentFile.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ parseHI
266266
parseHI hiPath = do
267267
dir <- asks (parent . ctxFile)
268268
result <-
269-
liftIO $ Iface.fromFile hiPath `catchAnyDeep` \e -> pure (Left (show e))
269+
liftIO $ catchAnyDeep
270+
(Iface.fromFile hiPath)
271+
(\e -> pure (Left (displayException e)))
270272
case result of
271273
Left msg -> do
272274
prettyStackDevL

src/Stack/Config/Docker.hs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ import Stack.Types.Resolver
2020
data ConfigDockerException
2121
= ResolverNotSupportedException !(Maybe Project) !(Maybe AbstractResolver)
2222
-- ^ Only LTS resolvers are supported for default image tag.
23-
deriving Typeable
23+
deriving (Show, Typeable)
2424

25-
-- | Show instance for StackDockerConfigException.
26-
instance Show ConfigDockerException where
27-
show (ResolverNotSupportedException mproject maresolver) =
25+
instance Exception ConfigDockerException where
26+
displayException (ResolverNotSupportedException mproject maresolver) =
2827
concat
2928
[ "Error: [S-8575]\n"
3029
, "Resolver not supported for Docker images:\n "
@@ -36,8 +35,6 @@ instance Show ConfigDockerException where
3635
, T.unpack dockerImageArgName
3736
, "' explicitly, in your configuration file."]
3837

39-
instance Exception ConfigDockerException
40-
4138
-- | Add a default Docker tag name to a given base image.
4239
addDefaultTag
4340
:: MonadThrow m

src/Stack/Config/Nix.hs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,20 @@ data ConfigNixException
2727
-- ^ Nix can't be given packages and a shell file at the same time
2828
| GHCMajorVersionUnspecified
2929
| OnlyGHCSupported
30-
deriving Typeable
30+
deriving (Show, Typeable)
3131

32-
instance Show ConfigNixException where
33-
show NixCannotUseShellFileAndPackagesException =
32+
instance Exception ConfigNixException where
33+
displayException NixCannotUseShellFileAndPackagesException =
3434
"Error: [S-2726]\n"
3535
++ "You cannot have packages and a shell-file filled at the same time \
3636
\in your nix-shell configuration."
37-
show GHCMajorVersionUnspecified =
37+
displayException GHCMajorVersionUnspecified =
3838
"Error: [S-9317]\n"
3939
++ "GHC major version not specified."
40-
show OnlyGHCSupported =
40+
displayException OnlyGHCSupported =
4141
"Error: [S-8605]\n"
4242
++ "Only GHC is supported by 'stack --nix'."
4343

44-
instance Exception ConfigNixException
45-
4644
-- | Interprets NixOptsMonoid options.
4745
nixOptsFromMonoid
4846
:: HasRunner env

0 commit comments

Comments
 (0)