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

Commit 1042fde

Browse files
committed
Prevent hie crash if apply-refact crashes
Catch all SomeExceptions that apply-refact might throw
1 parent faee856 commit 1042fde

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

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

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

77
import Control.Arrow
88
import Control.Exception ( IOException
9+
, SomeException
910
, try
1011
)
1112
import Control.Lens hiding ( List )
@@ -251,10 +252,15 @@ applyHint fp mhint fileMap = do
251252
-- If we provide "applyRefactorings" with "Just (1,13)" then
252253
-- the "Redundant bracket" hint will never be executed
253254
-- because SrcSpan (1,20,??,??) doesn't contain position (1,13).
254-
appliedFile <- liftIO $ applyRefactorings Nothing commands fp
255-
diff <- ExceptT $ Right <$> makeDiffResult fp (T.pack appliedFile) fileMap
256-
liftIO $ logm $ "applyHint:diff=" ++ show diff
257-
return diff
255+
res <- liftIO
256+
(try $ applyRefactorings Nothing commands fp :: IO (Either SomeException String))
257+
case res of
258+
Right appliedFile -> do
259+
diff <- ExceptT $ Right <$> makeDiffResult fp (T.pack appliedFile) fileMap
260+
liftIO $ logm $ "applyHint:diff=" ++ show diff
261+
return diff
262+
Left err ->
263+
throwE (show err)
258264

259265
-- | Gets HLint ideas for
260266
getIdeas :: MonadIO m => FilePath -> Maybe OneHint -> ExceptT String m [Idea]

0 commit comments

Comments
 (0)