Commit 66797dc0 authored by simonmar's avatar simonmar
Browse files

[project @ 2005-01-26 12:58:09 by simonmar]

fileLoop: catch InvalidArgument and behave as for EOF (i.e. terminate
the session).  This means that the user can close stdin to end a GHCi
session, but it also means that the tests that run programs which use
getContents inside GHCi won't crash because stdin has been closed.
parent 1f516e82
{-# OPTIONS -#include "Linker.h" #-}
-----------------------------------------------------------------------------
-- $Id: InteractiveUI.hs,v 1.183 2005/01/18 12:18:19 simonpj Exp $
-- $Id: InteractiveUI.hs,v 1.184 2005/01/26 12:58:09 simonmar Exp $
--
-- GHC Interactive User Interface
--
......@@ -68,6 +68,7 @@ import Control.Monad as Monad
import Foreign.StablePtr ( newStablePtr )
import GHC.Exts ( unsafeCoerce# )
import GHC.IOBase ( IOErrorType(InvalidArgument) )
import Data.IORef ( IORef, newIORef, readIORef, writeIORef )
......@@ -308,8 +309,14 @@ fileLoop hdl prompt = do
when prompt (io (putStr (mkPrompt mod imports)))
l <- io (IO.try (hGetLine hdl))
case l of
Left e | isEOFError e -> return ()
| otherwise -> io (ioError e)
Left e | isEOFError e -> return ()
| InvalidArgument <- etype -> return ()
| otherwise -> io (ioError e)
where etype = ioeGetErrorType e
-- treat InvalidArgument in the same way as EOF:
-- this can happen if the user closed stdin, or
-- perhaps did getContents which closes stdin at
-- EOF.
Right l ->
case remove_spaces l of
"" -> fileLoop hdl prompt
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment