Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 99c71d0

Browse files
committed
Avoid crash in case of nonsensical hoogle db
1 parent bfa37db commit 99c71d0

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Haskell/Ide/Engine/Plugin/Hoogle.hs

+11-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
module Haskell.Ide.Engine.Plugin.Hoogle where
44

55
import Control.Monad.IO.Class
6+
import Control.Monad (join)
7+
import Control.Exception
68
import Data.Aeson
79
import Data.Bifunctor
810
import Data.Maybe
@@ -42,7 +44,11 @@ hoogleDescriptor plId = PluginDescriptor
4244

4345
-- ---------------------------------------------------------------------
4446

45-
data HoogleError = NoDb | NoResults deriving (Eq,Ord,Show)
47+
data HoogleError
48+
= NoDb
49+
| DbFail T.Text
50+
| NoResults
51+
deriving (Eq,Ord,Show)
4652

4753
newtype HoogleDb = HoogleDb (Maybe FilePath)
4854

@@ -53,6 +59,8 @@ hoogleErrorToIdeError NoResults =
5359
IdeError PluginError "No results found" Null
5460
hoogleErrorToIdeError NoDb =
5561
IdeError PluginError "Hoogle database not found. Run hoogle generate to generate" Null
62+
hoogleErrorToIdeError (DbFail msg) =
63+
IdeError PluginError ("Hoogle failed with following error: " <> msg) Null
5664

5765
instance ExtensionClass HoogleDb where
5866
initialValue = HoogleDb Nothing
@@ -215,8 +223,8 @@ lookupCmd' n term = do
215223
runHoogleQuery :: Maybe FilePath -> T.Text -> ([Target] -> Either HoogleError a) -> IO (Either HoogleError a)
216224
runHoogleQuery Nothing _ _ = return $ Left NoDb
217225
runHoogleQuery (Just db) quer f = do
218-
res <- searchHoogle db quer
219-
return (f res)
226+
res <- try (searchHoogle db quer) :: IO (Either ErrorCall [Target])
227+
return . join $ bimap (DbFail . T.pack . show) f res
220228

221229

222230
-- | Run a query for Hoogle on the given Hoogle database.

0 commit comments

Comments
 (0)