Skip to content

Commit

Permalink
Merge pull request #5918 from commercialhaskell/re5911-configcmd
Browse files Browse the repository at this point in the history
Re #5911 Tidy up exceptions in Stack.ConfigCmd
  • Loading branch information
mpilgrem authored Oct 28, 2022
2 parents 909d5a7 + 445a56f commit 21ab7f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
14 changes: 6 additions & 8 deletions doc/maintainers/stack_errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ to take stock of the errors that Stack itself can raise, by reference to the
= NixCannotUseShellFileAndPackagesException
~~~

- `Stack.ConfigCmd.ConfigCmdException`

~~~haskell
= NoProjectConfigAvailable
~~~

- `Stack.Types.Build.StackBuildException`

~~~haskell
Expand Down Expand Up @@ -442,14 +448,6 @@ to take stock of the errors that Stack itself can raise, by reference to the
<path>
~~~
* `Stack.ConfigCmd.cfgCmdSet`:
~~~text
config command used when no project configuration available
~~~
`throwString`
* `Stack.Config.Nix.nixCompiler`:
~~~text
Expand Down
13 changes: 12 additions & 1 deletion src/Stack/ConfigCmd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ import Stack.Types.Config
import Stack.Types.Resolver
import System.Environment (getEnvironment)

data ConfigCmdException
= NoProjectConfigAvailable
deriving (Typeable)

instance Show ConfigCmdException where
show NoProjectConfigAvailable =
"Error: config command used when no project configuration available"

instance Exception ConfigCmdException

data ConfigCmdSet
= ConfigCmdSetResolver !(Unresolved AbstractResolver)
| ConfigCmdSetSystemGhc !CommandScope !Bool
Expand Down Expand Up @@ -72,7 +82,8 @@ cfgCmdSet cmd = do
case mstackYaml of
PCProject stackYaml -> pure stackYaml
PCGlobalProject -> liftM (</> stackDotYaml) (getImplicitGlobalProjectDir conf)
PCNoProject _extraDeps -> throwString "config command used when no project configuration available" -- maybe modify the ~/.stack/config.yaml file instead?
PCNoProject _extraDeps -> throwIO NoProjectConfigAvailable
-- maybe modify the ~/.stack/config.yaml file instead?
CommandScopeGlobal -> pure (configUserConfigPath conf)
rawConfig <- liftIO (readFileUtf8 (toFilePath configFilePath))
config <- either throwM pure (Yaml.decodeEither' $ encodeUtf8 rawConfig)
Expand Down

0 comments on commit 21ab7f5

Please sign in to comment.