Skip to content

Commit 1526f90

Browse files
committed
Catch errors in the 8.10 code path
1 parent 18d20e0 commit 1526f90

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)
@@ -350,6 +350,9 @@ applyHint ide nfp mhint =
350350
runExceptT $ do
351351
let runAction' :: Action a -> IO a
352352
runAction' = runAction "applyHint" ide
353+
let errorHandlers = [ Handler $ \e -> return (Left (show (e :: IOException)))
354+
, Handler $ \e -> return (Left (show (e :: ErrorCall)))
355+
]
353356
ideas <- bimapExceptT showParseError id $ ExceptT $ runAction' $ getIdeas nfp
354357
let ideas' = maybe ideas (`filterIdeas` ideas) mhint
355358
let commands = map ideaRefactoring ideas'
@@ -387,10 +390,8 @@ applyHint ide nfp mhint =
387390
-- We have to reparse extensions to remove the invalid ones
388391
let (enabled, disabled, _invalid) = parseExtensions $ map show exts
389392
let refactExts = map show $ enabled ++ disabled
390-
(Right <$> applyRefactorings Nothing commands temp refactExts) `catches`
391-
[ Handler $ \e -> return (Left (show (e :: IOException)))
392-
, Handler $ \e -> return (Left (show (e :: ErrorCall)))
393-
]
393+
(Right <$> applyRefactorings Nothing commands temp refactExts)
394+
`catches` errorHandlers
394395
#else
395396
mbParsedModule <- liftIO $ runAction' $ getParsedModule nfp
396397
res <-
@@ -403,7 +404,8 @@ applyHint ide nfp mhint =
403404
let dflags = ms_hspp_opts modsum
404405
(anns', modu') <-
405406
ExceptT $ return $ postParseTransform (Right (anns, [], dflags, modu)) normalLayout
406-
liftIO (Right <$> applyRefactorings' Nothing commands anns' modu')
407+
liftIO $ (Right <$> applyRefactorings' Nothing commands anns' modu')
408+
`catches` errorHandlers
407409
#endif
408410
case res of
409411
Right appliedFile -> do

0 commit comments

Comments
 (0)