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

Commit 4fe7097

Browse files
committed
Prevent hie crash if hlint crashes
1 parent 70c2420 commit 4fe7097

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,25 @@ lintCmd = CmdSync $ \uri -> do
105105
-- AZ:TODO: Why is this in IdeGhcM?
106106
lintCmd' :: Uri -> IdeGhcM (IdeResult PublishDiagnosticsParams)
107107
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)
108+
eitherErrorResult <- GM.withMappedFile fp $ \file' ->
109+
liftIO (try $ runExceptT $ runLintCmd file' [] :: IO (Either SomeException (Either [Diagnostic] [Idea])))
110+
111+
case eitherErrorResult of
112+
Left err ->
113+
return
114+
$ IdeResultFail (IdeError PluginError
115+
(T.pack $ "lintCmd: " ++ show err) Null)
116+
Right res -> case res of
117+
Left diags ->
118+
return
119+
(IdeResultOk
120+
(PublishDiagnosticsParams (filePathToUri fp) $ List diags)
121+
)
122+
Right fs ->
123+
return
124+
$ IdeResultOk
125+
$ PublishDiagnosticsParams (filePathToUri fp)
126+
$ List (map hintToDiagnostic $ stripIgnores fs)
116127

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

0 commit comments

Comments
 (0)