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

Commit 47b5281

Browse files
authored
Merge pull request #1174 from fendor/fix-hoogle-no-database
Avoid crash in case of nonsensical hoogle db
2 parents 39bc399 + 99c71d0 commit 47b5281

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
@@ -216,8 +224,8 @@ lookupCmd' n term = do
216224
runHoogleQuery :: Maybe FilePath -> T.Text -> ([Target] -> Either HoogleError a) -> IO (Either HoogleError a)
217225
runHoogleQuery Nothing _ _ = return $ Left NoDb
218226
runHoogleQuery (Just db) quer f = do
219-
res <- searchHoogle db quer
220-
return (f res)
227+
res <- try (searchHoogle db quer) :: IO (Either ErrorCall [Target])
228+
return . join $ bimap (DbFail . T.pack . show) f res
221229

222230

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

0 commit comments

Comments
 (0)