Skip to content

Commit 0fecd88

Browse files
committed
Catch errors in the 8.10 code path
1 parent 86d1efe commit 0fecd88

File tree

1 file changed

+8
-6
lines changed
  • plugins/hls-hlint-plugin/src/Ide/Plugin

1 file changed

+8
-6
lines changed

plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module Ide.Plugin.Hlint
2020
import Refact.Apply
2121
import Control.Arrow ((&&&))
2222
import Control.DeepSeq
23+
import Control.Exception
2324
import Control.Lens ((^.))
2425
import Control.Monad
2526
import Control.Monad.IO.Class
@@ -37,7 +38,6 @@ import Development.IDE.Core.Rules (defineNoFile)
3738
import Development.IDE.Core.Shake (getDiagnostics)
3839

3940
#ifdef HLINT_ON_GHC_LIB
40-
import Control.Exception
4141
import Data.List (nub)
4242
import "ghc-lib" GHC hiding (DynFlags(..), ms_hspp_opts)
4343
import "ghc-lib-parser" GHC.LanguageExtensions (Extension)
@@ -351,6 +351,9 @@ applyHint ide nfp mhint =
351351
runExceptT $ do
352352
let runAction' :: Action a -> IO a
353353
runAction' = runAction "applyHint" ide
354+
let errorHandlers = [ Handler $ \e -> return (Left (show (e :: IOException)))
355+
, Handler $ \e -> return (Left (show (e :: ErrorCall)))
356+
]
354357
ideas <- bimapExceptT showParseError id $ ExceptT $ runAction' $ getIdeas nfp
355358
let ideas' = maybe ideas (`filterIdeas` ideas) mhint
356359
let commands = map ideaRefactoring ideas'
@@ -388,10 +391,8 @@ applyHint ide nfp mhint =
388391
-- We have to reparse extensions to remove the invalid ones
389392
let (enabled, disabled, _invalid) = parseExtensions $ map show exts
390393
let refactExts = map show $ enabled ++ disabled
391-
(Right <$> applyRefactorings Nothing commands temp refactExts) `catches`
392-
[ Handler $ \e -> return (Left (show (e :: IOException)))
393-
, Handler $ \e -> return (Left (show (e :: ErrorCall)))
394-
]
394+
(Right <$> applyRefactorings Nothing commands temp refactExts)
395+
`catches` errorHandlers
395396
#else
396397
mbParsedModule <- liftIO $ runAction' $ getParsedModule nfp
397398
res <-
@@ -404,7 +405,8 @@ applyHint ide nfp mhint =
404405
let dflags = ms_hspp_opts modsum
405406
(anns', modu') <-
406407
ExceptT $ return $ postParseTransform (Right (anns, [], dflags, modu)) normalLayout
407-
liftIO (Right <$> applyRefactorings' Nothing commands anns' modu')
408+
liftIO $ (Right <$> applyRefactorings' Nothing commands anns' modu')
409+
`catches` errorHandlers
408410
#endif
409411
case res of
410412
Right appliedFile -> do

0 commit comments

Comments
 (0)