-
Notifications
You must be signed in to change notification settings - Fork 795
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
Convert deserializers to use exceptions #1584
Merged
wezrule
merged 8 commits into
nanocurrency:master
from
wezrule:convert_deserialization_to_use_exceptions
Feb 5, 2019
Merged
Convert deserializers to use exceptions #1584
wezrule
merged 8 commits into
nanocurrency:master
from
wezrule:convert_deserialization_to_use_exceptions
Feb 5, 2019
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cryptocode
approved these changes
Jan 25, 2019
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.
Approving code pending rebase, though the question is if we want to introduce exception handling as the code base is currently error code based.
1ec53bd
to
7270b4f
Compare
argakiig
pushed a commit
that referenced
this pull request
Feb 5, 2019
* Initial changes * Bit of cleanup and formatting * More formatting * See if including the boost file directly, fixes build on travis * Remove new exception type and spitting out exception details * Constructors with hashables should check for errors as before * Error condition incorrect * Add changes to confirm_req::deserialization
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
quality improvements
This item indicates the need for or supplies changes that improve maintainability
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While working on Issue #1374 I have to (de)serialize a new object type which had a few member variables. While looking at the existing serialization functions to the data store I thought it would be more readable to use exceptions. It turns something like this:
Into:
The previous (existing) form doesn't scale well, some places have 6 members and it's not unfeasible to expect some to have many more in the future. It is in my opinion much more readable and looks more like the serializing functions:
So it is much easier to spot mistakes. In an ideal world the exceptions wouldn't be handled as low level here and instead much higher up the stack, so it could look even cleaner however as deserializer functions return a boolean and there are many of them which would need changing I have left this for now to reduce the risk of regression.
A few things were done:
try_lexical_convert
which returns a boolean whilelexical_cast
throws. In a previous commit I created my own exception type (deserialization_error
) and also std::cerr'ed any exceptions. However this is too low level, so gets output in tests for instance so I am just keeping it has it currently is.nano::mdb_val::operator std::array<char, 64> () const
demonstrates that returning errors can be happily ignored, something that doesn't happen with exceptions. In c++17 there is the [[no_discard]] attribute however but this cannot be used yet. core/test/network.cpp also checks the returned error condition now.