-
Notifications
You must be signed in to change notification settings - Fork 110
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
errors: Low level (de)ser errors #1017
Conversation
See the following report for details: cargo semver-checks output
|
bc6b9ea
to
8645171
Compare
8645171
to
34a047f
Compare
v1.1: rebased on main |
34a047f
to
169e3ea
Compare
v2:
|
169e3ea
to
1a6908f
Compare
What about adding context to LLDeserError in new deserialization framework? |
New deserialization framework needs more context.
@@ -37,6 +37,8 @@ pub enum FrameError { | |||
pub enum ParseError { |
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.
Please remind me, is the current plan to get rid of ParseError completely?
If not, we need to remember to add non_exhaustive to it, and other errors (like FrameError above).
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.
I ultimately would like to get rid of ParseError
. It will be decoupled into multiple error types, which will be more specific and what's the most important - they will be typed. As of now, most of the ParseError
s are stringified (e.g. converted to QueryError::InvalidMessage
).
There is a similar issue with a FrameError
, however I'm not planning to remove it. I'd like to decouple it and introduce a distinction between FrameSerializationError
(for client frames) and FrameDeserializationError
(for server frames). These two could be then represented as variants of {Query/NewSession}Error
(and not stringified to QueryError::InvalidMessage
, which is something we currently do).
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.
I love it when github decides to post my review but without the main comment I wrote :) Posting again...
I think those are good changes in the right direction in general.
Please explain, because I don't remember from our discussion and I can't understand from commits: why do we have a distinction between deserialization error and low level deserialization error? The errors are a public API, why should a user of a library care which internal layer of the driver returned the error and not just what the error is?
Note: If we don't have something like this, whole error refactor should be finished with tests that will present and assert the error messages in various conditions. That way we can see them without writing one-off code to trigger those errors.
LowLevelDeserializationError is strictly connected to the CQL protocol types deserialization layer. On top of it, there is DeserializationError, which carries the meaning of a logical error during deserialization. |
`write_` functions from types module needlesly return `ParseError` (which is a really broad error type), when `std::num::TryFromIntError` can be returned for all of them. This commit changes the return error type from `ParseError` to `std::num::TryFromIntError`. It also adjusts the caller sites of these functions (simply by applying '?' operator).
Introduced a `LowLevelDeserializationError`. This error is a more narrow type than the `ParseError` and is destined to be returned from `types.rs` deserialization functions (read_*). Another profit is that the returned errors will be typed, and not stringified (current `ParseError::BadIncomingData`).
This commit replaces the return error type in `read_*` functions from ParseError to LowLevelDeserializationError.
The `value::mk_deser_err` utility function will be used in a `deser_cql_value`. We need to increase the visibility scope of this function.
Previously, there was a cycle in error types. Precisely, the `value::BuiltinDeserializationErrorKind::GenericParseError` contained a `ParseError`. Meanwhile, ParseError contained a DeserializationError. This commit removes this cycle by removing the former dependency. The GenericParseError variant will be replaced by a couple of new variants: - BadDate -> deserialization of one of date's fields failed - BadDecimalScale -> deserialization of decimal's scale failed - RawCqlBytesReadError -> failed to read raw bytes of cql value from frame - CustomTypeNotSupported(String) The main issue was that `deser_cql_value` would return a ParseError. In this commit, we change it so it returns DeserializationError. Other functions from deserialization module are adjusted accordingly as well. We also changed the variant `TabletParsingError::Parse(ParseError)` to `TabletParsingError::DeserializationError(DeserializationError)`, because the tablets module makes use of `deser_cql_value`.
1a6908f
to
4c929ce
Compare
v3:
|
I didn't read the changes yet, so my question may be inaccurate. |
I don't think it will change in the future. I also wanted to introduce another layer represented as LowLevelSerializationError (marked as non_exhaustive). The problem is that, as of now we would unnecessarily broaden the error type (from std::num::TryFromIntError to LowLevelSerializationError) in functions, which contradicts the approach we took for LLDeserError. |
Ref: #519
Motivation
This commit is a small step forward to resolving the issues related to errors in rust driver. The main goal of this PR is to get rid of
ParseError
fromframe::types
module.As a bonus, the newly introduced deserialization module is adjusted as well. Thanks to that, we remove the cycle in error types (
DeserializationError <-> ParseError
).Changes
LowLevelDeserializationError
types::read_*
functions toLowLevelDeserializationError
value::BuiltinDeserializationErrorKind::GenericParseError
with new variantsdeser_cql_value
to DeserializationErrorTabletsParsingError::Parse
withTabletsParsingError::DeserializationError
Pre-review checklist
[ ] I added relevant tests for new features and bug fixes.[ ] I have adjusted the documentation in./docs/source/
.[ ] I added appropriateFixes:
annotations to PR description.