Skip to content

Commit be688e9

Browse files
committed
Re commercialhaskell#5911 Tidy up exceptions in various modules
Minor refactoring and Haddock comments.
1 parent a6bc270 commit be688e9

24 files changed

Lines changed: 577 additions & 529 deletions

doc/maintainers/stack_errors.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ to take stock of the errors that Stack itself can raise, by reference to the
9191
| DeletionFailures [(Path Abs Dir, SomeException)]
9292
~~~
9393

94-
- `Stack.Config.Docker.StackDockerConfigExeceiption`
94+
- `Stack.Config.Docker.ConfigDockerException`
9595

9696
~~~haskell
9797
= ResolverNotSupportedException (Maybe Project) (Maybe AbstractResolver)
@@ -194,7 +194,7 @@ to take stock of the errors that Stack itself can raise, by reference to the
194194
| Can'tUseWiredInName PackageName
195195
~~~
196196

197-
- `Stack.Nix.StackNixException`
197+
- `Stack.Nix.NixException`
198198

199199
~~~haskell
200200
= CannotDetermineProjectRoot
@@ -410,7 +410,7 @@ to take stock of the errors that Stack itself can raise, by reference to the
410410
| ComponentNotParsedBug
411411
~~~
412412

413-
- `Stack.Types.Resolver.BuildPlanTypesException`
413+
- `Stack.Types.Resolver.TypesResolverException`
414414

415415
~~~haskell
416416
= ParseResolverException Text

src/Control/Concurrent/Execute.hs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ import Stack.Prelude
1818
import Data.List (sortBy)
1919
import qualified Data.Set as Set
2020

21+
-- | Type representing exceptions thrown by functions exported by the
22+
-- "Control.Concurrent.Execute" module.
23+
data ExecuteException
24+
= InconsistentDependencies
25+
deriving Typeable
26+
27+
instance Show ExecuteException where
28+
show InconsistentDependencies =
29+
"Inconsistent dependencies were discovered while executing your build \
30+
\plan. This should never happen, please report it as a bug to the \
31+
\Stack team."
32+
33+
instance Exception ExecuteException
34+
2135
data ActionType
2236
= ATBuild
2337
-- ^ Action for building a package's library and executables. If
@@ -61,17 +75,6 @@ data ExecuteState = ExecuteState
6175
, esKeepGoing :: Bool
6276
}
6377

64-
data ExecuteException
65-
= InconsistentDependencies
66-
deriving Typeable
67-
instance Exception ExecuteException
68-
69-
instance Show ExecuteException where
70-
show InconsistentDependencies =
71-
"Inconsistent dependencies were discovered while executing your build \
72-
\plan. This should never happen, please report it as a bug to the \
73-
\Stack team."
74-
7578
runActions :: Int -- ^ threads
7679
-> Bool -- ^ keep going after one task has failed
7780
-> [Action]

src/Stack/BuildPlan.hs

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

6161
instance Show BuildPlanException where
6262
show (SnapshotNotFound snapName) = unlines

src/Stack/Clean.hs

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

3030
instance Show CleanException where
3131
show (NonLocalPackages pkgs) =

src/Stack/Config/Docker.hs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,28 @@ import Stack.Types.Config
1515
import Stack.Types.Docker
1616
import Stack.Types.Resolver
1717

18+
-- | Type representing exceptions thrown by functions exported by the
19+
-- "Stack.Config.Docker" module.
20+
data ConfigDockerException
21+
= ResolverNotSupportedException !(Maybe Project) !(Maybe AbstractResolver)
22+
-- ^ Only LTS resolvers are supported for default image tag.
23+
deriving Typeable
24+
25+
-- | Show instance for StackDockerConfigException.
26+
instance Show ConfigDockerException where
27+
show (ResolverNotSupportedException mproject maresolver) =
28+
concat
29+
[ "Resolver not supported for Docker images:\n "
30+
, case (mproject, maresolver) of
31+
(Nothing, Nothing) -> "no resolver specified"
32+
(_, Just aresolver) -> T.unpack $ utf8BuilderToText $ display aresolver
33+
(Just project, Nothing) -> T.unpack $ utf8BuilderToText $ display $ projectResolver project
34+
, "\nUse an LTS resolver, or set the '"
35+
, T.unpack dockerImageArgName
36+
, "' explicitly, in your configuration file."]
37+
38+
instance Exception ConfigDockerException
39+
1840
-- | Add a default Docker tag name to a given base image.
1941
addDefaultTag
2042
:: MonadThrow m
@@ -76,25 +98,3 @@ dockerOptsFromMonoid mproject maresolver DockerOptsMonoid{..} = do
7698
where emptyToNothing Nothing = Nothing
7799
emptyToNothing (Just s) | null s = Nothing
78100
| otherwise = Just s
79-
80-
-- | Exceptions thrown by Stack.Docker.Config.
81-
data StackDockerConfigException
82-
= ResolverNotSupportedException !(Maybe Project) !(Maybe AbstractResolver)
83-
-- ^ Only LTS resolvers are supported for default image tag.
84-
deriving (Typeable)
85-
86-
-- | Exception instance for StackDockerConfigException.
87-
instance Exception StackDockerConfigException
88-
89-
-- | Show instance for StackDockerConfigException.
90-
instance Show StackDockerConfigException where
91-
show (ResolverNotSupportedException mproject maresolver) =
92-
concat
93-
[ "Resolver not supported for Docker images:\n "
94-
, case (mproject, maresolver) of
95-
(Nothing, Nothing) -> "no resolver specified"
96-
(_, Just aresolver) -> T.unpack $ utf8BuilderToText $ display aresolver
97-
(Just project, Nothing) -> T.unpack $ utf8BuilderToText $ display $ projectResolver project
98-
, "\nUse an LTS resolver, or set the '"
99-
, T.unpack dockerImageArgName
100-
, "' explicitly, in your configuration file."]

src/Stack/Config/Nix.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ 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 Typeable
3131

3232
instance Show ConfigNixException where
3333
show NixCannotUseShellFileAndPackagesException =

src/Stack/ConfigCmd.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ import Stack.Types.Config
4040
import Stack.Types.Resolver
4141
import System.Environment (getEnvironment)
4242

43+
-- | Type repesenting exceptions thrown by functions exported by the
44+
-- "Stack.ConfigCmd" module.
4345
data ConfigCmdException
4446
= NoProjectConfigAvailable
45-
deriving (Typeable)
47+
deriving Typeable
4648

4749
instance Show ConfigCmdException where
4850
show NoProjectConfigAvailable =

src/Stack/Coverage.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ import RIO.Process
4646
import Trace.Hpc.Tix
4747
import Web.Browser (openBrowser)
4848

49+
-- | Type representing exceptions thrown by functions exported by the
50+
-- "Stack.Coverage" module.
4951
data CoverageException
5052
= NonTestSuiteTarget PackageName
5153
| NoTargetsOrTixSpecified

src/Stack/Docker.hs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010

1111
-- | Run commands in Docker containers
1212
module Stack.Docker
13-
(dockerCmdName
14-
,dockerHelpOptName
15-
,dockerPullCmdName
16-
,entrypoint
17-
,preventInContainer
18-
,pull
19-
,reset
20-
,reExecArgName
21-
,StackDockerException(..)
22-
,getProjectRoot
23-
,runContainerAndExit
13+
( dockerCmdName
14+
, dockerHelpOptName
15+
, dockerPullCmdName
16+
, entrypoint
17+
, preventInContainer
18+
, pull
19+
, reset
20+
, reExecArgName
21+
, DockerException(..)
22+
, getProjectRoot
23+
, runContainerAndExit
2424
) where
2525

2626
import Stack.Prelude

src/Stack/Ghci.hs

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,36 @@ import System.IO (putStrLn)
5252
import System.IO.Temp (getCanonicalTemporaryDirectory)
5353
import System.Permissions (setScriptPerms)
5454

55+
-- | Type representing exceptions thrown by functions exported by the
56+
-- "Stack.Ghci" module.
57+
data GhciException
58+
= InvalidPackageOption String
59+
| LoadingDuplicateModules
60+
| MissingFileTarget String
61+
| Can'tSpecifyFilesAndTargets
62+
| Can'tSpecifyFilesAndMainIs
63+
| GhciTargetParseException [Text]
64+
deriving Typeable
65+
66+
instance Show GhciException where
67+
show (InvalidPackageOption name) =
68+
"Failed to parse --package option " ++ name
69+
show LoadingDuplicateModules = unlines
70+
[ "Not attempting to start ghci due to these duplicate modules."
71+
, "Use --no-load to try to start it anyway, without loading any modules (but these are still likely to cause errors)"
72+
]
73+
show (MissingFileTarget name) =
74+
"Cannot find file target " ++ name
75+
show Can'tSpecifyFilesAndTargets =
76+
"Cannot use 'stack ghci' with both file targets and package targets"
77+
show Can'tSpecifyFilesAndMainIs =
78+
"Cannot use 'stack ghci' with both file targets and --main-is flag"
79+
show (GhciTargetParseException xs) =
80+
show (TargetParseException xs) ++
81+
"\nNote that to specify options to be passed to GHCi, use the --ghci-options flag"
82+
83+
instance Exception GhciException
84+
5585
-- | Command-line options for GHC.
5686
data GhciOpts = GhciOpts
5787
{ ghciTargets :: ![Text]
@@ -100,34 +130,6 @@ type ModuleMap = Map ModuleName (Map (Path Abs File) (Set (PackageName, NamedCom
100130
unionModuleMaps :: [ModuleMap] -> ModuleMap
101131
unionModuleMaps = M.unionsWith (M.unionWith S.union)
102132

103-
data GhciException
104-
= InvalidPackageOption String
105-
| LoadingDuplicateModules
106-
| MissingFileTarget String
107-
| Can'tSpecifyFilesAndTargets
108-
| Can'tSpecifyFilesAndMainIs
109-
| GhciTargetParseException [Text]
110-
deriving (Typeable)
111-
112-
instance Exception GhciException
113-
114-
instance Show GhciException where
115-
show (InvalidPackageOption name) =
116-
"Failed to parse --package option " ++ name
117-
show LoadingDuplicateModules = unlines
118-
[ "Not attempting to start ghci due to these duplicate modules."
119-
, "Use --no-load to try to start it anyway, without loading any modules (but these are still likely to cause errors)"
120-
]
121-
show (MissingFileTarget name) =
122-
"Cannot find file target " ++ name
123-
show Can'tSpecifyFilesAndTargets =
124-
"Cannot use 'stack ghci' with both file targets and package targets"
125-
show Can'tSpecifyFilesAndMainIs =
126-
"Cannot use 'stack ghci' with both file targets and --main-is flag"
127-
show (GhciTargetParseException xs) =
128-
show (TargetParseException xs) ++
129-
"\nNote that to specify options to be passed to GHCi, use the --ghci-options flag"
130-
131133
-- | Launch a GHCi session for the given local package targets with the
132134
-- given options and configure it with the load paths and extensions
133135
-- of those targets.

0 commit comments

Comments
 (0)