Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,323
    • Issues 4,323
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 367
    • Merge Requests 367
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #8213

Closed
Open
Opened Sep 02, 2013 by Niklas Hambüchen@nh2Reporter

Bad error message when using lazy IO to read from closed handle

Today I accidentally wrote this code:

import System.IO
import Data.ByteString.Lazy as BSL

filesEqual :: FilePath -> FilePath -> IO Bool
filesEqual f1 f2 = do
  equal <- withBinaryFile f1 ReadMode $ \h1 ->
    withBinaryFile f2 ReadMode $ \h2 -> do
      c1 <- BSL.hGetContents h1
      c2 <- BSL.hGetContents h2
      return (c1 == c2)
  return $! equal

main = filesEqual "test.hs" "test.hs" >>= print

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

test: test.hs: 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?

Edited Mar 10, 2019 by thomie
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#8213