Fail (NG) on command format errors

This commit is contained in:
Nikolay Yakimov 2016-01-08 21:37:51 +03:00
parent 9b512c3e6b
commit 64a45fa510

View File

@ -6,6 +6,7 @@ import Control.Applicative
import Control.Monad import Control.Monad
import Data.Typeable (Typeable) import Data.Typeable (Typeable)
import Data.List import Data.List
import Data.List.Split
import Exception import Exception
import Language.Haskell.GhcMod import Language.Haskell.GhcMod
import Language.Haskell.GhcMod.Internal hiding (MonadIO,liftIO) import Language.Haskell.GhcMod.Internal hiding (MonadIO,liftIO)
@ -86,10 +87,15 @@ legacyInteractiveLoop asyncSymbolDb world = do
interactiveHandlers = interactiveHandlers =
[ GHandler $ \(e :: ExitCode) -> throw e [ GHandler $ \(e :: ExitCode) -> throw e
, GHandler $ \(InvalidCommandLine e) -> do , GHandler $ \(InvalidCommandLine e) -> do
gmErrStrLn $ either ("Invalid command line: "++) Prelude.id e let err = notGood $ either ("Invalid command line: "++) Prelude.id e
return "" liftIO $ do
putStr err
exitFailure
, GHandler $ \(SomeException e) -> gmErrStrLn (show e) >> return "" , GHandler $ \(SomeException e) -> gmErrStrLn (show e) >> return ""
] ]
notGood msg = "NG " ++ escapeNewlines msg
escapeNewlines = replace "\n" "\\n" . replace "\\n" "\\\\n"
replace needle replacement = intercalate replacement . splitOn needle
getFileSourceFromStdin :: IO String getFileSourceFromStdin :: IO String
getFileSourceFromStdin = do getFileSourceFromStdin = do