Skip to content

Commit 7914b10

Browse files
committed
Make Stack.IDE exceptions prettier
1 parent 16f1a65 commit 7914b10

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

doc/maintainers/stack_errors.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ to take stock of the errors that Stack itself can raise, by reference to the
156156
[S-3025] | HoogleDatabaseNotFound
157157
~~~
158158

159+
- `Stack.IDE.IdePrettyException`
160+
161+
~~~haskell
162+
[S-9208] = FileTargetIsInvalidAbsFile
163+
~~~
164+
159165
- `Stack.Init.InitException`
160166

161167
~~~haskell

src/Stack/IDE.hs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,22 @@ import Stack.Types.SourceMap
5858
( ProjectPackage (..), SMWanted (..), ppComponentsMaybe )
5959
import System.IO ( putStrLn )
6060

61-
-- | Type representing exceptions thrown by functions exported by the
61+
-- | Type representing \'pretty\' exceptions thrown by functions exported by the
6262
-- "Stack.IDE" module.
63-
newtype IdeException
64-
= MissingFileTarget String
63+
newtype IdePrettyException
64+
= FileTargetIsInvalidAbsFile String
6565
deriving (Show, Typeable)
6666

67-
instance Exception IdeException where
68-
displayException (MissingFileTarget name) =
69-
"Error: [S-9208]\n"
70-
++ "Cannot find file target " ++ name ++ "."
67+
instance Pretty IdePrettyException where
68+
pretty (FileTargetIsInvalidAbsFile name) =
69+
"[S-9208]"
70+
<> line
71+
<> fillSep
72+
[ flow "Cannot work out a valid path for file target"
73+
, style File (fromString name) <> "."
74+
]
75+
76+
instance Exception IdePrettyException
7177

7278
-- | Function underlying the @stack ide packages@ command. List packages in the
7379
-- project.
@@ -196,7 +202,7 @@ preprocessTarget rawTarget =
196202
let fp = T.unpack rawTarget
197203
mpath <- forgivingResolveFile' fp
198204
case mpath of
199-
Nothing -> throwM (MissingFileTarget fp)
205+
Nothing -> prettyThrowM (FileTargetIsInvalidAbsFile fp)
200206
Just path -> pure path
201207
pure (Just fileTarget)
202208
else pure Nothing

0 commit comments

Comments
 (0)