-
Notifications
You must be signed in to change notification settings - Fork 112
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: Replace ParseError
with CqlResponseParseError
in frame::response
module
#1026
Conversation
See the following report for details: cargo semver-checks output
|
You haven't checked nor crossed out the I added relevant tests for new features and bug fixes option. Do you believe any tests are relevant here? |
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.
Awesome changes!
Mainly some nits.
9093ca9
to
bc37fbe
Compare
v2:
|
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.
Awesome work! This is a huge step in direction of clean and informative error handling.
bc37fbe
to
fe2f625
Compare
Rebased on main |
fe2f625
to
0b1bf1e
Compare
v2.1: addressed nit review comments |
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, thank you for finally making errors orderly!
scylla-cql/src/frame/frame_errors.rs
Outdated
#[error("'Schema_change' response deserialization failed: {0}")] | ||
SchemaChangeEventParseError(#[from] SchemaChangeEventParseError), |
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.
@wprzytula @muzarski Do you think that this variant should be present here?
CQL events are always sent on a separate channel (-1) which handles only that - so there should be no way for a user to get this error
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 think that you meant CqlResponseParseError::CqlEventParseError
variant. I think that you are right. If so, then I'll remove this variant from public API.
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 see no easy way to decouple event handling from ordinary response handling. Thus, we need a common error type for both.
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.
It's true. Now the question is whether we want to introduce new public error type excluding this specific variant? I'm not sure if there is much sense to do so.
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'd leave it as is for now.
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 see your point (why would handling events have its own error variants in QueryError), but the size of such refactor makes it out of this PR's scope IMO.
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.
It's not only about Events. CqlResponseParseError
has the following variants:
CqlErrorParseError
CqlAuthChallengeParseError
CqlAuthSuccessParseError
CqlAuthenticateParseError
CqlSupportedParseError
CqlEventParseError
CqlResultParseError
If I'm not mistaken only first and last are possible for the user to encounter in QueryError (other ones only possible in NewSessionError). I understand that it may increase the amount of changes, but I think we should avoid creating such types anyway. It makes it much harder for users who want to handle errors in a different way than just printing them.
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.
OK, this is quite convincing. I suggest that @muzarski analyse all possible error routes in the driver and try to redesign the error hierarchy so that user-facing error types don't contain variants that the user is never supposed to see.
One idea is that we can introduce two layers of error handling:
- a lower-lever one, resembling one introduced in this PR,
- a higher-level one, restricting variants to those that a user really might see. It should be organised with the user's perspective in mind rather than reflect the driver's inner architecture.
0b1bf1e
to
b29d0fc
Compare
ref: #1056 |
b29d0fc
to
b5f48d5
Compare
Rebased on main |
The Display implementation for this error already says: "could not convert slice to array". No need to provide more context.
Introduced an error type returned when we fail to deserialize a RESULT response type to SET KEYSPACE request.
Introduced an error type returned when we fail to deserialize a RESULT::Schema_change response.
The `allow` is not needed anymore.
Introduced an error type returned when deserialization of table spec fails.
Introduced an error type returned when we fail to deserialize a CQL type.
An error type returned when we fail to deserialize table's column specs.
Replaced `read_int().try_into()` with a utility function that does exactly the same. This way, the caller doesn't have to handle two separate errors.
Introduced an error returned when deserialization of Result/PreparedMetadata fails.
Error returned when we fail to deserialize a RESULT::Prepared CQL response.
An error type returned when deserialization of RESULT::Rows response fails.
An error type returned when RESULT response deserialization fails.
Introduced an error type returned when we fail to deserialize either StatusChangeEvent or TopologyChangeEvent.
Introduced an error type returned when we fail to deserialize an EVENT response.
In the following commit we want to introduce a CqlResponseParseError type which will be a new variant of `[Query/NewSession]Error`. These two error types implement a `Clone` trait. They require a `Clone`, since there is some cloning of errors in `history` module. This is why, we need to derive Clone for all of the types introduces in previous commits. Unfortunately, the `std::io::Error` does not implement Clone. This is why we need to wrap any appearing `std::io::Error` with `Arc`, so the enum types encapsulating it can derive Clone.
b5f48d5
to
46d639b
Compare
Ref: #519
Depends on: #1017
Motivation
We ultimately want to get rid of the
ParseError
. This error type is overloaded with a lot of variants which do not provide much context to the users. In addition, a lot of errors are stringified.This PR gets rid of
ParseError
from theframe::response
module which is responsible for CQL response deserialization. This is the place where the usage ofParseError
is abused the most.Changes
Types of response
There are multiple types of responses. We introduce a new error type for each of them, e.g.
CqlResultParseError
orCqlSupportedParseError
. I follow a bottom-to-top approach, starting from implementing an error types for CQL column type deserialization.Each commit introduces a new error type, which is firstly encapsulated by
ParseError
(so the higher level functions returningParseError
can apply ? operator). Once we exhaust all of the error variants that can be returned by some function, we introduce a new error type which encapsulates error types introduced in previous commits. These error types are then moved out of theParseError
(if possible, sometimes the functions are not exclusive toframe::response
module which is the only module addressed in this PR).Pre-review checklist
[ ] I added relevant tests for new features and bug fixes.[ ] I have adjusted the documentation in./docs/source/
.Fixes:
annotations to PR description.