@@ -57,6 +57,7 @@ import IRTS.CodegenCommon
5757import IRTS.System
5858
5959import Control.Category
60+import qualified Control.Exception as X
6061import Prelude hiding ((.), id)
6162import Data.List.Split (splitOn)
6263import Data.List (groupBy)
@@ -208,17 +209,29 @@ processNetCmd orig i h fn cmd
208209-- | Run a command on the server on localhost
209210runClient :: PortID -> String -> IO ()
210211runClient port str = withSocketsDo $ do
211− h <- connectTo "localhost" port
212+ res <- X.try (connectTo "localhost" port)
213+ case res of
214+ Right h -> do
212215 hSetEncoding h utf8
213216 hPutStrLn h str
214217 resp <- hGetResp "" h
215218 putStr resp
216219 hClose h
220+
221+ Left err -> do
222+ connectionError err
223+ exitWith (ExitFailure 1)
224+
217225 where hGetResp acc h = do eof <- hIsEOF h
218226 if eof then return acc
219227 else do l <- hGetLine h
220228 hGetResp (acc ++ l ++ "\n") h
221229
230+ connectionError :: X.SomeException -> IO ()
231+ connectionError _ =
232+ putStrLn "Unable to connect to a running Idris repl"
233+
234+
222235initIdeslaveSocket :: IO Handle
223236initIdeslaveSocket = do
224237 (sock, port) <- listenOnLocalhostAnyPort