Skip to content

Commit a6ae6a5

Browse files
authored
Merge pull request commercialhaskell#3879 from commercialhaskell/improved-parse-errors
Improved error messages for snapshot parse exceptions
2 parents 32a7fa2 + cb947f1 commit a6ae6a5

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Other enhancements:
4343
It is best used with ghc's equivalent flag,
4444
i.e. `stack build --keep-tmp-files --ghc-options=-keep-tmp-files`.
4545
See [#3857](https://github.com/commercialhaskell/stack/issues/3857)
46+
* Improved error messages for snapshot parse exceptions
4647

4748
Bug fixes:
4849

src/Stack/Snapshot.hs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ data SnapshotException
7575
| NeedResolverOrCompiler !Text
7676
| MissingPackages !(Set PackageName)
7777
| CustomResolverException !Text !(Either Request FilePath) !ParseException
78+
| InvalidStackageException !SnapName !String
7879
deriving Typeable
7980
instance Exception SnapshotException
8081
instance Show SnapshotException where
@@ -124,10 +125,20 @@ instance Show SnapshotException where
124125
show (CustomResolverException url loc e) = concat
125126
[ "Unable to load custom resolver "
126127
, T.unpack url
127-
, " from location\n"
128-
, show loc
128+
, " from "
129+
, case loc of
130+
Left _req -> "HTTP request"
131+
Right fp -> "local file:\n " ++ fp
129132
, "\nException: "
130-
, show e
133+
, case e of
134+
AesonException s -> s
135+
_ -> show e
136+
]
137+
show (InvalidStackageException snapName e) = concat
138+
[ "Unable to parse Stackage snapshot "
139+
, T.unpack (renderSnapName snapName)
140+
, ": "
141+
, e
131142
]
132143

133144
-- | Convert a 'Resolver' into a 'SnapshotDef'
@@ -146,7 +157,7 @@ loadResolver (ResolverStackage name) = do
146157
Left e -> throwIO e
147158
Right value ->
148159
case parseEither parseStackageSnapshot value of
149-
Left s -> throwIO $ AesonException s
160+
Left s -> throwIO $ InvalidStackageException name s
150161
Right x -> return x
151162
logDebug $ "Decoding build plan from: " <> T.pack (toFilePath fp)
152163
eres <- tryDecode
@@ -277,7 +288,7 @@ loadResolver (ResolverCustom url loc) = do
277288
WithJSONWarnings (sd0, mparentResolver, mcompiler) warnings <-
278289
liftIO (decodeFileEither fp) >>= either
279290
(throwM . CustomResolverException url loc)
280-
(either (throwM . AesonException) return . parseEither parseCustom)
291+
(either (throwM . CustomResolverException url loc . AesonException) return . parseEither parseCustom)
281292
logJSONWarnings (T.unpack url) warnings
282293
forM_ (sdLocations sd0) $ \loc' ->
283294
case loc' of

0 commit comments

Comments
 (0)