Skip to content

Commit

Permalink
Clear a STAN suggestion.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilgrem committed Oct 18, 2023
1 parent 87c1a5b commit 5c77029
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion doc/maintainers/stack_errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
In connection with considering Stack's support of the
[Haskell Error Index](https://errors.haskell.org/) initiative, this page seeks
to take stock of the errors that Stack itself can raise, by reference to the
`master` branch of the Stack repository. Last updated: 2023-10-16.
`master` branch of the Stack repository. Last updated: 2023-10-17.

* `GHC.GHC.Utils.GhcPkg.Main.Compat`

Expand Down Expand Up @@ -131,6 +131,7 @@ to take stock of the errors that Stack itself can raise, by reference to the
~~~haskell
[S-8251] = PackageIdNotFoundBug String
[S-2483] | ExecutableToRunNotFound
[S-8600] | NoPackageIdReportedBug
~~~

- `Stack.GhcPkg`
Expand Down
16 changes: 12 additions & 4 deletions src/Stack/Exec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import qualified Data.List as L
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import qualified Data.Text as T
import RIO.NonEmpty ( head, nonEmpty )
import RIO.Process ( exec )
import Stack.Build ( build )
import Stack.Build.Target ( NeedTargets (..) )
Expand Down Expand Up @@ -56,17 +57,21 @@ instance Exception ExecException where
data ExecPrettyException
= PackageIdNotFoundBug !String
| ExecutableToRunNotFound
| NoPackageIdReportedBug
deriving (Show, Typeable)

instance Pretty ExecPrettyException where
pretty (PackageIdNotFoundBug name) = bugPrettyReport "[S-8251]" $
"Could not find the package id of the package" <+>
style Target (fromString name)
<> "."
fillSep
[ flow "Could not find the package id of the package"
, style Target (fromString name) <> "."
]
pretty ExecutableToRunNotFound =
"[S-2483]"
<> line
<> flow "No executables found."
pretty NoPackageIdReportedBug = bugPrettyReport "S-8600" $
flow "execCmd: findGhcPkgField returned Just \"\"."

instance Exception ExecPrettyException

Expand Down Expand Up @@ -128,7 +133,10 @@ execCmd ExecOpts {..} =
pkg <- getGhcPkgExe
mId <- findGhcPkgField pkg [] name "id"
case mId of
Just i -> pure (L.head $ words (T.unpack i))
Just i -> maybe
(prettyThrowIO NoPackageIdReportedBug)
(pure . head)
(nonEmpty $ words $ T.unpack i)
-- should never happen as we have already installed the packages
_ -> prettyThrowIO (PackageIdNotFoundBug name)

Expand Down

0 comments on commit 5c77029

Please sign in to comment.