-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Network.TLS.IO: Return errors as Left #224
Conversation
There is no API change here, but two things that were thown as exceptions from
namely |
Have you checked if the exceptions are rethrown downstream? |
@ocheron "downstream"? You mean in |
Could be anything actually, but first hs-tls yes. |
Does this mean that |
I need to look at this more carefully. Will do so some time this week. |
Here's my full review after checking the code path in more details. What happens in your scenario at https://github.com/erikd-ambiata/test-https-client-resource-vanished/ is that when you kill one end of the connection, at the other end setEOF is called from readExact because we can distinguish there an end-of-stream Error_Packet from other Error_Packet exceptions raised by disengageRecord. I don't think it's safe to remove the setEOF call. Also exception Error_EOF is caught with safeHandleError_EOF, so that recvData returns an empty bytestring. Moving away from exceptions is good, but the behaviour should not change. I'm not against wrapping an end-of-stream Error_Packet inside a |
f8d95e8
to
f6e88db
Compare
I've updated the PR so that the behavior at the API level of |
This is just my opinion but I don't like
And I would like to have:
If advantages of |
I agree. The problem is that the existing code uses exceptions for flow control. In most languages this is considered a code smell. Exceptions are usually reserved for exceptional circumstances. One of the things that the commit is "fixing" is I consider this the first patch in a series of patches that would remove all throwing of exceptions within TLS, catch all exceptions at the interface between TLS and lower levels and convert them into errors that a represented in the types. TLS would then provide at API of total functions to clients of TLS. I know Haskell is not a total programming language, but it is possible to program in it as if it is. The function
I agree, the function signature does not express the partiality that result from exceptions, but removing the
|
I didn't realize disengageRecord uses throwError and not throwCore. I still think the setEOF call in readExact should be kept there. |
@ocheron Sorry, I don't understand that comment. I don't see how this PR changes the circumstances in which |
I agree with |
@erikd The current |
One more item to discuss. Can
|
@kazu-yamamoto EOF is not the only failure state that is be communicated via the |
@erikd Yes. But other true errors can be thrown. |
I finally recognized that Now I fully support @erikd's approach. |
@ocheron You are correct. I will update the PR. |
Previously these were thrown as exceptions even though the error types were correct to return then as a Left. Closes: haskell-tls#220
f6e88db
to
03d7234
Compare
LGTM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Merged. Thank you for your contribution! |
This has been merged. Closing. |
Previously these were thrown as exceptions even though the error
types were correct to return then as a Left.
Closes: #220