[GHC] #9236: hGetContents leads to late/silent failures

GHC ghc-devs at haskell.org
Tue Jun 24 18:09:12 UTC 2014


#9236: hGetContents leads to late/silent failures
-------------------------------------+------------------------------------
        Reporter:  dfeuer            |            Owner:
            Type:  feature request   |           Status:  new
        Priority:  normal            |        Milestone:
       Component:  Compiler          |          Version:  7.6.3
      Resolution:                    |         Keywords:
Operating System:  Unknown/Multiple  |     Architecture:  Unknown/Multiple
 Type of failure:  None/Unknown      |       Difficulty:  Unknown
       Test Case:                    |       Blocked By:
        Blocking:                    |  Related Tickets:
-------------------------------------+------------------------------------

Comment (by dfeuer):

 Specifically, it looks like all that we need is to change
 {{{
 #!haskell
 lazyRead :: Handle -> IO String
 lazyRead handle =
    unsafeInterleaveIO $
         withHandle "hGetContents" handle $ \ handle_ -> do
         case haType handle_ of
           ClosedHandle     -> return (handle_, "")
           SemiClosedHandle -> lazyReadBuffered handle handle_
           _ -> ioException
                   (IOError (Just handle) IllegalOperation "hGetContents"
                         "illegal handle type" Nothing Nothing)
 }}}

 to

 {{{
 #!haskell
 lazyRead :: Handle -> IO String
 lazyRead handle =
    unsafeInterleaveIO $
         withHandle "hGetContents" handle $ \ handle_ -> do
         case haType handle_ of
           ClosedHandle     -> return (handle_, error "You can't get blood
 from a stone.")
           SemiClosedHandle -> lazyReadBuffered handle handle_
           _ -> ioException
                   (IOError (Just handle) IllegalOperation "hGetContents"
                         "illegal handle type" Nothing Nothing)
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9236#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list