@@ -57,6 +57,7 @@ import IRTS.CodegenCommon
57import IRTS.System
57import IRTS.System
59import Control.Category
59import Control.Category
60+import qualified Control.Exception as X
60import Prelude hiding ((.), id)
61import Prelude hiding ((.), id)
61import Data.List.Split (splitOn)
62import Data.List.Split (splitOn)
62import Data.List (groupBy)
63import Data.List (groupBy)
@@ -208,17 +209,29 @@ processNetCmd orig i h fn cmd
208-- | Run a command on the server on localhost
209-- | Run a command on the server on localhost
209runClient :: PortID -> String -> IO ()
210runClient :: PortID -> String -> IO ()
210runClient port str = withSocketsDo $ do
211runClient port str = withSocketsDo $ do
211− h <- connectTo "localhost" port
212+ res <- X.try (connectTo "localhost" port)
212 hSetEncoding h utf8
215 hSetEncoding h utf8
213 hPutStrLn h str
216 hPutStrLn h str
214 resp <- hGetResp "" h
217 resp <- hGetResp "" h
215 putStr resp
218 putStr resp
223+ exitWith (ExitFailure 1)
217 where hGetResp acc h = do eof <- hIsEOF h
225 where hGetResp acc h = do eof <- hIsEOF h
218 if eof then return acc
226 if eof then return acc
219 else do l <- hGetLine h
227 else do l <- hGetLine h
220 hGetResp (acc ++ l ++ "\n") h
228 hGetResp (acc ++ l ++ "\n") h
230+ connectionError :: X.SomeException -> IO ()
232+ putStrLn "Unable to connect to a running Idris repl"
222initIdeslaveSocket :: IO Handle
235initIdeslaveSocket :: IO Handle
223initIdeslaveSocket = do
236initIdeslaveSocket = do
224 (sock, port) <- listenOnLocalhostAnyPort
237 (sock, port) <- listenOnLocalhostAnyPort