From 54fe4a0edbdddfbdc2acc43edde2b061ca5b399b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=B6ber?= Date: Wed, 13 Jan 2016 04:49:38 +0100 Subject: [PATCH] Replace fromJust with fromJustNote everywhere --- Language/Haskell/GhcMod/Browse.hs | 3 ++- Language/Haskell/GhcMod/Cradle.hs | 3 ++- Language/Haskell/GhcMod/Monad/Types.hs | 6 ++++-- Language/Haskell/GhcMod/Stack.hs | 4 ++-- Language/Haskell/GhcMod/Target.hs | 5 +++-- Setup.hs | 3 ++- ghc-mod.cabal | 1 + 7 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Language/Haskell/GhcMod/Browse.hs b/Language/Haskell/GhcMod/Browse.hs index d2b3c79..05bc969 100644 --- a/Language/Haskell/GhcMod/Browse.hs +++ b/Language/Haskell/GhcMod/Browse.hs @@ -3,6 +3,7 @@ module Language.Haskell.GhcMod.Browse ( BrowseOpts(..) ) where +import Safe import Control.Applicative import Control.Exception (SomeException(..)) import Data.Char @@ -49,7 +50,7 @@ browse opts pkgmdl = do goHomeModule = runGmlT [Right mdlname] $ do processExports opts =<< tryModuleInfo =<< G.findModule mdlname Nothing - tryModuleInfo m = fromJust <$> G.getModuleInfo m + tryModuleInfo m = fromJustNote "browse, tryModuleInfo" <$> G.getModuleInfo m (mpkg, mdl) = splitPkgMdl pkgmdl mdlname = G.mkModuleName mdl diff --git a/Language/Haskell/GhcMod/Cradle.hs b/Language/Haskell/GhcMod/Cradle.hs index fe31fd6..fe2b179 100644 --- a/Language/Haskell/GhcMod/Cradle.hs +++ b/Language/Haskell/GhcMod/Cradle.hs @@ -19,6 +19,7 @@ import Language.Haskell.GhcMod.Stack import Language.Haskell.GhcMod.Logging import Language.Haskell.GhcMod.Error +import Safe import Control.Applicative import Control.Monad.Trans.Maybe import Data.Maybe @@ -46,7 +47,7 @@ findCradle' dir = run $ , sandboxCradle dir , plainCradle dir ] - where run a = fillTempDir =<< (fromJust <$> runMaybeT a) + where run a = fillTempDir =<< (fromJustNote "findCradle'" <$> runMaybeT a) findSpecCradle :: (GmLog m, IOish m, GmOut m) => FilePath -> m Cradle findSpecCradle dir = do diff --git a/Language/Haskell/GhcMod/Monad/Types.hs b/Language/Haskell/GhcMod/Monad/Types.hs index 0588117..c94efcc 100644 --- a/Language/Haskell/GhcMod/Monad/Types.hs +++ b/Language/Haskell/GhcMod/Monad/Types.hs @@ -73,6 +73,8 @@ import Language.Haskell.GhcMod.Monad.Out import Language.Haskell.GhcMod.Monad.Newtypes import Language.Haskell.GhcMod.Monad.Orphans () +import Safe + import GHC import DynFlags import Exception @@ -116,13 +118,13 @@ instance (MonadIO m, MonadBaseControl IO m) => GhcMonad (GmlT m) where -- | Get the underlying GHC session gmlGetSession :: (MonadIO m, MonadBaseControl IO m) => GmlT m HscEnv gmlGetSession = do - ref <- gmgsSession . fromJust . gmGhcSession <$> gmsGet + ref <- gmgsSession . fromJustNote "gmlGetSession" . gmGhcSession <$> gmsGet liftIO $ readIORef ref -- | Set the underlying GHC session gmlSetSession :: (MonadIO m, MonadBaseControl IO m) => HscEnv -> GmlT m () gmlSetSession a = do - ref <- gmgsSession . fromJust . gmGhcSession <$> gmsGet + ref <- gmgsSession . fromJustNote "gmlSetSession" . gmGhcSession <$> gmsGet liftIO $ flip writeIORef a ref instance GhcMonad LightGhc where diff --git a/Language/Haskell/GhcMod/Stack.hs b/Language/Haskell/GhcMod/Stack.hs index e919761..498430e 100644 --- a/Language/Haskell/GhcMod/Stack.hs +++ b/Language/Haskell/GhcMod/Stack.hs @@ -16,7 +16,7 @@ module Language.Haskell.GhcMod.Stack where - +import Safe import Control.Applicative import Control.Exception as E import Control.Monad @@ -51,7 +51,7 @@ patchStackPrograms _crdl progs = return progs getStackEnv :: (IOish m, GmOut m, GmLog m) => FilePath -> m (Maybe StackEnv) getStackEnv projdir = U.withDirectory_ projdir $ runMaybeT $ do env <- map (liToTup . splitOn ": ") . lines <$> readStack ["path"] - let look k = fromJust $ lookup k env + let look k = fromJustNote "getStackEnv" $ lookup k env return StackEnv { seDistDir = look "dist-dir" , seBinPath = splitSearchPath $ look "bin-path" diff --git a/Language/Haskell/GhcMod/Target.hs b/Language/Haskell/GhcMod/Target.hs index b1ffe9a..7985d1a 100644 --- a/Language/Haskell/GhcMod/Target.hs +++ b/Language/Haskell/GhcMod/Target.hs @@ -40,6 +40,7 @@ import Language.Haskell.GhcMod.LightGhc import Language.Haskell.GhcMod.CustomPackageDb import Language.Haskell.GhcMod.Output +import Safe import Data.Maybe import Data.Monoid as Monoid import Data.Either @@ -188,13 +189,13 @@ targetGhcOptions crdl sefnmn = do let cns = filter (/= ChSetupHsName) $ Map.keys mcs gmLog GmDebug "" $ strDoc $ "Could not find a component assignment, falling back to picking library component in cabal file." - return $ gmcGhcOpts $ fromJust $ Map.lookup (head cns) mcs + return $ gmcGhcOpts $ fromJustNote "targetGhcOptions, no-assignment" $ Map.lookup (head cns) mcs else do when noCandidates $ throwError $ GMECabalCompAssignment mdlcs let cn = pickComponent candidates - return $ gmcGhcOpts $ fromJust $ Map.lookup cn mcs + return $ gmcGhcOpts $ fromJustNote "targetGhcOptions" $ Map.lookup cn mcs resolvedComponentsCache :: IOish m => FilePath -> Cached (GhcModT m) GhcModState diff --git a/Setup.hs b/Setup.hs index 982ec70..00db893 100755 --- a/Setup.hs +++ b/Setup.hs @@ -8,6 +8,7 @@ import Distribution.Simple.InstallDirs as ID import Distribution.Simple.LocalBuildInfo import Distribution.PackageDescription +import Safe import Control.Arrow import Control.Applicative import Control.Monad @@ -99,7 +100,7 @@ xInstallTarget pd lbi fn = do libexecdir' = fromPathTemplate (libexecdir idirtpl) pd_extended = onlyExePackageDesc [exe] pd - install_target = fromJust $ installTarget exe + install_target = fromJustNote "xInstallTarget" $ installTarget exe install_target' = ID.substPathTemplate env install_target -- $libexec isn't a real thing :/ so we have to simulate it install_target'' = substLibExec' libexecdir' install_target' diff --git a/ghc-mod.cabal b/ghc-mod.cabal index 8de41e9..7fc6222 100644 --- a/ghc-mod.cabal +++ b/ghc-mod.cabal @@ -186,6 +186,7 @@ Library , fclabels == 2.0.* , extra == 1.4.* , pipes == 4.1.* + , safe < 0.4 && >= 0.3.9 if impl(ghc < 7.8) Build-Depends: convertible if impl(ghc < 7.5)