Cleanup errors and logging a bit

This commit is contained in:
Daniel Gröber
2015-03-04 21:48:21 +01:00
parent bc71877dcf
commit f0ea445a9b
41 changed files with 242 additions and 456 deletions

View File

@@ -35,7 +35,7 @@ module Language.Haskell.GhcMod.Error (
import Control.Arrow
import Control.Exception
import Control.Monad.Error
import Control.Monad.Error hiding (MonadIO, liftIO)
import qualified Data.Set as Set
import Data.List
import Data.Version
@@ -49,9 +49,9 @@ import Config (cProjectVersion, cHostPlatformString)
import Paths_ghc_mod (version)
import Language.Haskell.GhcMod.Types
import Language.Haskell.GhcMod.Monad.Types
import Language.Haskell.GhcMod.Pretty
type GmError m = MonadError GhcModError m
gmCsfeDoc :: GMConfigStateFileError -> Doc
@@ -101,10 +101,15 @@ gmeDoc e = case e of
GMECabalCompAssignment ctx ->
text "Could not find a consistent component assignment for modules:" $$
(nest 4 $ foldr ($+$) empty $ map ctxDoc ctx) $$
empty $$
text "Try this and that"
text "" $$
text "- Are you sure all these modules exist?" $$
text "- Maybe try enabling test suites and or benchmarks:" $$
nest 4 (backticks $ text "cabal configure --enable-tests --enable-benchmarks") $$
text "- To find out which components ghc-mod knows about try:" $$
nest 4 (backticks $ text "ghc-mod debug")
where
backticks d = char '`' <> d <> char '`'
ctxDoc = moduleDoc *** compsDoc
>>> first (<> colon) >>> uncurry (flip hang 4)
@@ -177,10 +182,11 @@ tryFix action f = do
data GHandler m a = forall e . Exception e => GHandler (e -> m a)
gcatches :: ExceptionMonad m => m a -> [GHandler m a] -> m a
gcatches :: (MonadIO m, ExceptionMonad m) => m a -> [GHandler m a] -> m a
gcatches io handlers = io `gcatch` gcatchesHandler handlers
gcatchesHandler :: ExceptionMonad m => [GHandler m a] -> SomeException -> m a
gcatchesHandler :: (MonadIO m, ExceptionMonad m)
=> [GHandler m a] -> SomeException -> m a
gcatchesHandler handlers e = foldr tryHandler (liftIO $ throw e) handlers
where tryHandler (GHandler handler) res
= case fromException e of

View File

@@ -54,5 +54,5 @@ gmLog level loc' doc = do
msg = gmRenderDoc $ gmLogLevelDoc level <+> loc <+> doc
when (Just level <= level') $
liftIO $ hPutStrLn stderr msg
liftIO $ hPutStr stderr msg
gmlJournal (GhcModLog Nothing [(level, render loc, msg)])

View File

@@ -29,6 +29,7 @@ import System.FilePath
import System.IO.Unsafe
import Language.Haskell.GhcMod.Types
import Language.Haskell.GhcMod.Monad.Types
import Language.Haskell.GhcMod.Error
import Language.Haskell.GhcMod.Read
import Language.Haskell.GhcMod.Utils hiding (dropWhileEnd)

View File

@@ -17,6 +17,8 @@
module Language.Haskell.GhcMod.Pretty where
import Control.Arrow hiding ((<+>))
import Data.Char
import Data.List
import Text.PrettyPrint
import Language.Haskell.GhcMod.Types
@@ -56,7 +58,7 @@ warnDoc :: Doc -> Doc
warnDoc d = text "Warning" <+>: d
strDoc :: String -> Doc
strDoc str = doc str
strDoc str = doc (dropWhileEnd isSpace str)
where
doc :: String -> Doc
doc = lines

View File

@@ -68,7 +68,7 @@ defaultOptions :: Options
defaultOptions = Options {
outputStyle = PlainStyle
, lineSeparator = LineSeparator "\0"
, logLevel = GmPanic
, logLevel = GmException
-- , ghcProgram = "ghc"
, cabalProgram = "cabal"
, ghcUserOptions= []

View File

@@ -25,6 +25,7 @@ import Control.Arrow
import Control.Applicative
import Data.Char
import Language.Haskell.GhcMod.Error
import Language.Haskell.GhcMod.Monad.Types
import Exception
import System.Directory (getCurrentDirectory, setCurrentDirectory, doesFileExist)
import System.Process (readProcess)