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

Commit e6d249e

Browse files
committed
Prevent hie crash if hlint crashes
Catch all IOExceptions that hlint might throw
1 parent 1a58d5c commit e6d249e

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
module Haskell.Ide.Engine.Plugin.ApplyRefact where
66

77
import Control.Arrow
8-
import Control.Lens hiding (List)
8+
import Control.Exception ( IOException
9+
, try
10+
)
11+
import Control.Lens hiding ( List )
912
import Control.Monad.IO.Class
1013
import Control.Monad.Trans.Except
1114
import Data.Aeson hiding (Error)
@@ -105,14 +108,25 @@ lintCmd = CmdSync $ \uri -> do
105108
-- AZ:TODO: Why is this in IdeGhcM?
106109
lintCmd' :: Uri -> IdeGhcM (IdeResult PublishDiagnosticsParams)
107110
lintCmd' uri = pluginGetFile "lintCmd: " uri $ \fp -> do
108-
res <- GM.withMappedFile fp $ \file' -> liftIO $ runExceptT $ runLintCmd file' []
109-
case res of
110-
Left diags ->
111-
return (IdeResultOk (PublishDiagnosticsParams (filePathToUri fp) $ List diags))
112-
Right fs ->
113-
return $ IdeResultOk $
114-
PublishDiagnosticsParams (filePathToUri fp)
115-
$ List (map hintToDiagnostic $ stripIgnores fs)
111+
eitherErrorResult <- GM.withMappedFile fp $ \file' ->
112+
liftIO (try $ runExceptT $ runLintCmd file' [] :: IO (Either IOException (Either [Diagnostic] [Idea])))
113+
114+
case eitherErrorResult of
115+
Left err ->
116+
return
117+
$ IdeResultFail (IdeError PluginError
118+
(T.pack $ "lintCmd: " ++ show err) Null)
119+
Right res -> case res of
120+
Left diags ->
121+
return
122+
(IdeResultOk
123+
(PublishDiagnosticsParams (filePathToUri fp) $ List diags)
124+
)
125+
Right fs ->
126+
return
127+
$ IdeResultOk
128+
$ PublishDiagnosticsParams (filePathToUri fp)
129+
$ List (map hintToDiagnostic $ stripIgnores fs)
116130

117131
runLintCmd :: FilePath -> [String] -> ExceptT [Diagnostic] IO [Idea]
118132
runLintCmd fp args = do

0 commit comments

Comments
 (0)