@@ -15,6 +15,7 @@ import qualified Data.List as L
15
15
import qualified Data.Map.Strict as Map
16
16
import qualified Data.Set as Set
17
17
import qualified Data.Text as T
18
+ import RIO.NonEmpty ( head , nonEmpty )
18
19
import RIO.Process ( exec )
19
20
import Stack.Build ( build )
20
21
import Stack.Build.Target ( NeedTargets (.. ) )
@@ -56,17 +57,21 @@ instance Exception ExecException where
56
57
data ExecPrettyException
57
58
= PackageIdNotFoundBug ! String
58
59
| ExecutableToRunNotFound
60
+ | NoPackageIdReportedBug
59
61
deriving (Show , Typeable )
60
62
61
63
instance Pretty ExecPrettyException where
62
64
pretty (PackageIdNotFoundBug name) = bugPrettyReport " [S-8251]" $
63
- " Could not find the package id of the package" <+>
64
- style Target (fromString name)
65
- <> " ."
65
+ fillSep
66
+ [ flow " Could not find the package id of the package"
67
+ , style Target (fromString name) <> " ."
68
+ ]
66
69
pretty ExecutableToRunNotFound =
67
70
" [S-2483]"
68
71
<> line
69
72
<> flow " No executables found."
73
+ pretty NoPackageIdReportedBug = bugPrettyReport " S-8600" $
74
+ flow " execCmd: findGhcPkgField returned Just \"\" ."
70
75
71
76
instance Exception ExecPrettyException
72
77
@@ -128,7 +133,10 @@ execCmd ExecOpts {..} =
128
133
pkg <- getGhcPkgExe
129
134
mId <- findGhcPkgField pkg [] name " id"
130
135
case mId of
131
- Just i -> pure (L. head $ words (T. unpack i))
136
+ Just i -> maybe
137
+ (prettyThrowIO NoPackageIdReportedBug )
138
+ (pure . head )
139
+ (nonEmpty $ words $ T. unpack i)
132
140
-- should never happen as we have already installed the packages
133
141
_ -> prettyThrowIO (PackageIdNotFoundBug name)
134
142
0 commit comments