on master help sign in
Merge pull request #1854 from elliottt/client-connect-message
d3db066David Christiansen
src/Idris/REPL.hs+14−1
@@ -57,6 +57,7 @@ import IRTS.CodegenCommon
57import IRTS.System
57import IRTS.System
58
58
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)
213+ case res of
214+ Right h -> do
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
216 hClose h
219 hClose h
220+
221+ Left err -> do
222+ connectionError err
223+ exitWith (ExitFailure 1)
224+
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
221
229
230+ connectionError :: X.SomeException -> IO ()
231+ connectionError _ =
232+ putStrLn "Unable to connect to a running Idris repl"
233+
234+
222initIdeslaveSocket :: IO Handle
235initIdeslaveSocket :: IO Handle
223initIdeslaveSocket = do
236initIdeslaveSocket = do
224 (sock, port) <- listenOnLocalhostAnyPort
237 (sock, port) <- listenOnLocalhostAnyPort