Proposal: When possible, give more useful exceptions from rawSystem and friends

Ian Lynagh ian at well-typed.com
Sun Apr 28 15:36:24 CEST 2013


Hi all,

Currently, if you try to use rawSystem to run a program that doesn't
exist, you will just get a bad error code as a result, e.g. this
program:

    import System.IO.Error
    import System.Process

    main :: IO ()
    main = do (rawSystem "/bin/true" [] >>= print)
                `catchIOError` \e -> putStrLn ("Exc: " ++ show e)
              (rawSystem "/bin/false" [] >>= print)
                `catchIOError` \e -> putStrLn ("Exc: " ++ show e)
              (rawSystem "/non/existent" [] >>= print) 
                `catchIOError` \e -> putStrLn ("Exc: " ++ show e)
              putStrLn "Done"

prints:

    ExitSuccess
    ExitFailure 1
    ExitFailure 127
    Done

However, if we are on a platform that supports vfork, then we can pass
information from the child process back to the parent process as they
share address space. With the attached patch we instead get:

    ExitSuccess
    ExitFailure 1
    Exc: resolveProcessHandle: does not exist (No such file or directory)

(and it should be easy to also get "/non/existent" in the exception).


If there are platforms that don't support vfork, then they will still
give the old output. I haven't yet looked at whether we can also get
good exceptions on Windows (the patch won't build on Windows yet; I
still need to update the Windows-specific code).

I think that despite the possibility that some platforms may not be able
to support it, we should provide the better behaviour on platforms that
do.

What do you think?
And do you have any other comments on the patch?

(this proposal was inspired by
http://hackage.haskell.org/trac/ghc/ticket/7859).


Suggested discussion deadline: Mon 13 May 2013.


Thanks
Ian

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Factor-out-a-helper-function.patch
Type: text/x-diff
Size: 2275 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/libraries/attachments/20130428/9aab6be1/attachment.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-When-possible-give-more-useful-exceptions-from-rawSy.patch
Type: text/x-diff
Size: 15645 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/libraries/attachments/20130428/9aab6be1/attachment-0001.patch>


More information about the Libraries mailing list