Ticket #1868 (closed bug: wontfix)

Opened 6 years ago

Last modified 4 years ago

Exception fails all exception predicates

Reported by: Orphi Owned by:
Priority: normal Milestone: 6.12 branch
Component: libraries/base Version: 6.8.1
Keywords: Cc:
Operating System: Windows Architecture: x86
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

Attempting to operate on a file with an invalid filename (e.g., "C:\C:\") yields an "invalid parameter" exception. This exception appears to be a kind of IOError, yet it fails all 8 exception predicates.

test :: IO x -> IO ()
test a = do
  catch (a >> return ()) examine

examine :: IOError -> IO ()
examine ioe = do
  putStrLn $ "isAlreadyExistsError___" ++ show (isAlreadyExistsError   ioe)
  putStrLn $ "isDoesNotExistError    " ++ show (isDoesNotExistError    ioe)
  putStrLn $ "isAlreadyInUseError____" ++ show (isAlreadyInUseError    ioe)
  putStrLn $ "isFullError            " ++ show (isFullError            ioe)
  putStrLn $ "isEOFError_____________" ++ show (isEOFError             ioe)
  putStrLn $ "isIllegalOperation     " ++ show (isIllegalOperation     ioe)
  putStrLn $ "isPermissionError______" ++ show (isPermissionError      ioe)
  putStrLn $ "isUserError            " ++ show (isUserError            ioe)

Now try, for example, test (openFile "C:\\C:\\" ReadMode). All 8 predicates above return False. (However, if you do, say, test (error "no"), the catch function doesn't trap it at all because it's not an IOError.)

I was under the impression this is what the "illegal operation" type was for?

Change History

Changed 6 years ago by Orphi

  • version changed from 6.6.1 to 6.8.1

I can confirm the same behaviour in GHC 6.8.1. (Above report was actually against 6.6.1, but 6.8.1 appears no different.)

Changed 6 years ago by igloo

  • difficulty set to Unknown
  • milestone set to 6.10 branch

GHC currently has (in GHC.IOBase)

data IOErrorType
  -- Haskell 98:
  = AlreadyExists
  | NoSuchThing
  | ResourceBusy
  | ResourceExhausted
  | EOF
  | IllegalOperation
  | PermissionDenied
  | UserError
  -- GHC only:
  | UnsatisfiedConstraints
  | SystemError
  | ProtocolError
  | OtherError
  | InvalidArgument
  | InappropriateType
  | HardwareFault
  | UnsupportedOperation
  | TimeExpired
  | ResourceVanished
  | Interrupted
  | DynIOError Dynamic -- cheap&cheerful extensible IO error type.

I'm not sure what the right thing to do here is. The report is rather vague.

Changed 6 years ago by Orphi

Mmm, so there's actually quite a lot of different exception types that you can't distinguish between currently. That's nice.

I'm not really sure how some of these errors are meant to be different. For example, what's the difference between an IllegalOperation and an InvalidArgument? When would you issue one, when would you issue the other? Similarly, what conditions does SystemError cover that are not already covered by ProtocolError, HardwareFault and ResourceExhausted? Is there some documentation somewhere which states exactly what each type is meant to cover?

The documentation in Sytem.IO.Error seems to suggest that IllegalOperation is intended to be a "catch-all" for any error that doesn't fall under the other types. Looking at the above, it seems that's not the case.

I guess probably the best thing to do at this point is just add more predicates for detecting all the possible I/O exception types. But the commands in the quoted code seem to suggest that this would break compatibility with Haskell 98?

Basically, I'd just like to be able to write an exception handler and know which exception happened so I can decide what to do. Currently that seems to be harder than necessary.

Changed 4 years ago by igloo

  • milestone changed from 6.10 branch to 6.12 branch

Changed 4 years ago by igloo

  • status changed from new to closed
  • resolution set to wontfix

I'm going to close this ticket. To fix it properly we would need a library proposal, either to add more predicates, or preferably to move to a proper exception hierarchy.

Note: See TracTickets for help on using tickets.