Skip to content

[Question] purpose and encoding of ioe_filename #189

@hasufell

Description

@hasufell

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:

  1. set the field to Nothing and be done
  2. just use unpack (so convert [Word8] to [Char])... printing may look like garbage on UTF-8 configured systems
  3. 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
  4. 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    core-librariesGovernance of Core Libraries other than base

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions