Remove withErrorHandler, use liftExceptions instead
This commit is contained in:
@@ -2,6 +2,7 @@ module Language.Haskell.GhcMod.Utils where
|
||||
|
||||
|
||||
import MonadUtils (MonadIO, liftIO)
|
||||
import Exception (ExceptionMonad, gtry)
|
||||
import Control.Exception
|
||||
import Control.Monad.Error (MonadError(..), Error(..))
|
||||
import System.Directory (getCurrentDirectory, setCurrentDirectory)
|
||||
@@ -9,7 +10,7 @@ import System.Process (readProcessWithExitCode)
|
||||
import System.Exit (ExitCode(..))
|
||||
import System.IO (hPutStrLn, stderr)
|
||||
import System.IO.Error (tryIOError)
|
||||
|
||||
import Language.Haskell.GhcMod.Types
|
||||
|
||||
-- dropWhileEnd is not provided prior to base 4.5.0.0.
|
||||
dropWhileEnd :: (a -> Bool) -> [a] -> [a]
|
||||
@@ -53,11 +54,24 @@ tryFix :: MonadError e m => m a -> (e -> m ()) -> m a
|
||||
tryFix action fix = do
|
||||
action `catchError` \e -> fix e >> action
|
||||
|
||||
liftMonadError :: (MonadIO m, Error e, MonadError e m) => IO a -> m a
|
||||
liftMonadError action = do
|
||||
-- | 'IOException's thrown in the computation passed to this function will be
|
||||
-- converted to 'MonadError' failures using 'throwError'.
|
||||
liftIOExceptions :: (MonadIO m, Error e, MonadError e m) => IO a -> m a
|
||||
liftIOExceptions action = do
|
||||
res <- liftIO $ tryIOError action
|
||||
case res of
|
||||
Right a -> return a
|
||||
Left e -> case show e of
|
||||
"" -> throwError $ noMsg
|
||||
msg -> throwError $ strMsg msg
|
||||
|
||||
-- | Exceptions thrown in the computation passed to this function will be
|
||||
-- converted to 'MonadError' failures using 'throwError'.
|
||||
liftExceptions :: (MonadIO m, ExceptionMonad m, MonadError GhcModError m)
|
||||
=> m a
|
||||
-> m a
|
||||
liftExceptions action = do
|
||||
res <- gtry action
|
||||
case res of
|
||||
Right a -> return a
|
||||
Left e -> throwError $ GMEException e
|
||||
|
||||
Reference in New Issue
Block a user