-
Notifications
You must be signed in to change notification settings - Fork 18
Description
IOException
has the following definition:
-- |Exceptions that occur in the @IO@ monad.
-- An @IOException@ records a more specific error type, a descriptive
-- string and maybe the handle that was used when the error was
-- flagged.
data IOException
= IOError {
ioe_handle :: Maybe Handle, -- the handle used by the action flagging
-- the error.
ioe_type :: IOErrorType, -- what it was.
ioe_location :: String, -- location.
ioe_description :: String, -- error type specific information.
ioe_errno :: Maybe CInt, -- errno leading to this error, if any.
ioe_filename :: Maybe FilePath -- filename the error is related to.
}
Since ioe_filename
is Maybe FilePath
, APIs that use ByteString
or the new OsPath
have an awkward situation, where they have to decide what to do:
- set the field to
Nothing
and be done - just use
unpack
(so convert[Word8]
to[Char]
)... printing may look like garbage on UTF-8 configured systems - use e.g. decodeFS, which is the closest match to base API behavior at the FFI boundary, but it's not well-defined for non-utf8 encodings
- use something like
decodeWith (mkUTF8 TransliterateCodingFailure)
, which never fails and replaces with the closest visual match upon an illegal sequences
This confusion has stirred up debate over at unix: haskell/unix#279
The main question here really is: should ioe_filename
allow the caller to recover the original filename or is it just a descriptive field?
And then: if the former, which encoding do we pick? Right now, the unfortunate situation is that System.Posix.PosixPath.FilePath
uses method 4 and System.Posix.ByteString.FilePath
uses method 2. That's clearly undesirable. If we go for method 2 for both, how does the caller know? IMO, this needs to be documented in base. No one will look for this information in the unix modules, nor anticipate that behavior.
@bgamari @mpickering ... do GHC devs have an opinion?