Hi, cafe, I'm working in a program where I use many connections with Network.HTTP. Sometimes, connections are closed while my program is reading them, and an error appears: <socket: XXX>: Data.ByteString.hGetLine: invalid argument (Bad file descriptor) All I need is to handle this error. The function 'catch' doesn't work. I guess this error comes from a call to 'error' function, or something similar. What I can do? Thanks in advance, Daniel Díaz
On Friday 11 March 2011 17:04:16, Daniel Díaz wrote:
Hi, cafe,
I'm working in a program where I use many connections with Network.HTTP. Sometimes, connections are closed while my program is reading them, and an error appears:
<socket: XXX>: Data.ByteString.hGetLine: invalid argument (Bad file descriptor)
All I need is to handle this error. The function 'catch' doesn't work. I guess this error comes from a call to 'error' function, or something similar.
Control.Exception.catch can catch error calls. If you're using Prelude.catch, you probably should switch.
What I can do?
Thanks in advance, Daniel Díaz
On Fri, 11 Mar 2011, Daniel Fischer wrote:
On Friday 11 March 2011 17:04:16, Daniel Díaz wrote:
Hi, cafe,
I'm working in a program where I use many connections with Network.HTTP. Sometimes, connections are closed while my program is reading them, and an error appears:
<socket: XXX>: Data.ByteString.hGetLine: invalid argument (Bad file descriptor)
All I need is to handle this error. The function 'catch' doesn't work. I guess this error comes from a call to 'error' function, or something similar.
Control.Exception.catch can catch error calls. If you're using Prelude.catch, you probably should switch.
Using 'error' in such cases would be definitely wrong, since a connection closed by the other end of the connection is not a programming error but an exceptional situation that we must handle properly at runtime. Unfortunately it is not documented in bytestring package, what exceptions hGetLine can throw and the type IO does not tell us, too. (For alternatives see: http://www.haskell.org/pipermail/haskell-cafe/2011-March/089936.html) You may scan the exceptions in http://hackage.haskell.org/packages/archive/base/4.3.1.0/doc/html/Control-Ex... for types that may be responsible for invalid file descriptors. This should certainly be in IOException, but on the other hand, IOException is also what Prelude.catch catches.
Check out the spoon package on hackage. It's designed for these kinds of situations, and will wrap up common user-generated "pure" exceptions into a Maybe (and will return Nothing in the cases you describe) -Dan On Fri, Mar 11, 2011 at 11:04 AM, Daniel Díaz <danieldiaz@asofilak.es>wrote:
Hi, cafe,
I'm working in a program where I use many connections with Network.HTTP. Sometimes, connections are closed while my program is reading them, and an error appears:
<socket: XXX>: Data.ByteString.hGetLine: invalid argument (Bad file descriptor)
All I need is to handle this error. The function 'catch' doesn't work. I guess this error comes from a call to 'error' function, or something similar.
What I can do?
Thanks in advance, Daniel Díaz
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
On Fri, 11 Mar 2011, Daniel Peebles wrote:
Check out the spoon package on hackage. It's designed for these kinds of situations, and will wrap up common user-generated "pure" exceptions into a Maybe (and will return Nothing in the cases you describe)
This is a hack, since 'undefined' cannot be detected in general. The clean solution would be to find out where invalid file descriptors are detected in the IO code, and throw a real IOException instead of an 'error'.
It's a hack by design, to work around libraries that do the wrong thing. On Fri, Mar 11, 2011 at 4:07 PM, Henning Thielemann < lemming@henning-thielemann.de> wrote:
On Fri, 11 Mar 2011, Daniel Peebles wrote:
Check out the spoon package on hackage. It's designed for these kinds of
situations, and will wrap up common user-generated "pure" exceptions into a Maybe (and will return Nothing in the cases you describe)
This is a hack, since 'undefined' cannot be detected in general. The clean solution would be to find out where invalid file descriptors are detected in the IO code, and throw a real IOException instead of an 'error'.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (4)
-
Daniel Díaz -
Daniel Fischer -
Daniel Peebles -
Henning Thielemann