Skip to content
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

Should the message header decoder throw an exception on a Postgres exception? #4

Open
KayEss opened this issue Jun 1, 2017 · 2 comments
Labels

Comments

@KayEss
Copy link
Member

KayEss commented Jun 1, 2017

It isn't yet clear what the right behaviour here is. By throwing an exception it also isn't totally clear that the connection get ever get back into a state where another command can be issued through it. This is probably going to be needed for transaction rollbacks, and maybe other things.

What is a better idea here?

@KayEss KayEss added the question label Jun 1, 2017
@jtv
Copy link
Collaborator

jtv commented Jun 17, 2017

Sounds as if perhaps you want the message-header decoder to return an error, so that the higher-level code can choose to throw — after first getting itself into a sensible state in case the connection continues to get used. I wouldn't worry about the performance cost of getting back to a sensible state. "I want to fail really really fast all the time" is a pretty esoteric requirement.

If the header itself is incomplete or unintelligible, that's a different matter. In that case the header parser can't meet its postcondition and the connection can't get back to a sensible state, so bailing out is the only course of action.

@KayEss
Copy link
Member Author

KayEss commented Jun 18, 2017

I agree, so enter the monad :)

I think std::expected is going to be the way to do this, but that's held up in committee about wanting a full monadic solution, so that could be a while. Still, it'll be easy enough to write something that behaves the same way.

I think the header reader probably isn't where this ought to go. The code that decodes the packets needs to include the error packet type in their expectations -- this is likely to lead to a lot of code that doesn't handle errors very well though. I suspect that it should probably be like that nonetheless, together with a few places where trying to continue will throw.

The first thing I really need to understand I think is how the message flow changes after errors in a few places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants