[GHC] #8213: Bad error message when using lazy IO to read from closed handle
GHC
ghc-devs at haskell.org
Mon Sep 2 09:50:35 CEST 2013
#8213: Bad error message when using lazy IO to read from closed handle
------------------------------------+--------------------------------------
Reporter: nh2 | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Runtime System | Version: 7.6.3
Keywords: | Operating System: Unknown/Multiple
Architecture: Unknown/Multiple | Type of failure: Documentation bug
Difficulty: Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: |
------------------------------------+--------------------------------------
Today I accidentally wrote this code:
{{{
filesEqual :: FilePath -> FilePath -> IO Bool
filesEqual f1 f2 = do
equal <- withBinaryFile f1 ReadMode $ \f1 ->
withBinaryFile f2 ReadMode $ \f2 ->
c1 <- BSL.hGetContents h1
c2 <- BSL.hGetContents h2
return (c1 == c2)
return $! equal
}}}
The problem is that I should have done the forcing before the files are
closed:
{{{
return $! (c1 == c2)
}}}
I got the incredibly unhelpful error message
{{{
myprogram: myfile.txt: illegal operation
}}}
It took me 2 hours and strace to find out what was going on, especially
because around every file open() there are multiple things that map top
IllegalOperation (e.g. the ENOTTY from the ioctl that checks whether the
device is a TTY).
Can we give a better error message here, at least mentioning that the
problem has to do with closed (and GC'd) handles?
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8213>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list