From 64a45fa5102a3d18bf2707226ff8c1b864c77637 Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Fri, 8 Jan 2016 21:37:51 +0300 Subject: [PATCH] Fail (NG) on command format errors --- src/GHCMod.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/GHCMod.hs b/src/GHCMod.hs index 40340fc..3bf89ab 100644 --- a/src/GHCMod.hs +++ b/src/GHCMod.hs @@ -6,6 +6,7 @@ import Control.Applicative import Control.Monad import Data.Typeable (Typeable) import Data.List +import Data.List.Split import Exception import Language.Haskell.GhcMod import Language.Haskell.GhcMod.Internal hiding (MonadIO,liftIO) @@ -86,10 +87,15 @@ legacyInteractiveLoop asyncSymbolDb world = do interactiveHandlers = [ GHandler $ \(e :: ExitCode) -> throw e , GHandler $ \(InvalidCommandLine e) -> do - gmErrStrLn $ either ("Invalid command line: "++) Prelude.id e - return "" + let err = notGood $ either ("Invalid command line: "++) Prelude.id e + liftIO $ do + putStr err + exitFailure , 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 = do