Skip to content

Commit

Permalink
errors: replace CqlResponseParseError variant in QueryError
Browse files Browse the repository at this point in the history
Since requests triggered via user API, cannot receive a response
other than ERROR or RESULT, we need to narrow the response parsing
errors accordingly. Before this commit, we would hold a
CqlResponseParseError which contains a parsing errors for responses
that should never be returned by the server for user requests.

After hard work from previous commits, we can finally replace
this overloaded variant with two variants
- CqlResultParseError -> failed to deserialize RESULT response
- CqlErrorParseError -> failed to deserialize ERROR response

In case of failure of parsing other response, we will return a
QueryError::ProtocolError saying that server returned an unexpected
response. I think we should add more context to this error,
but let's leave it for other PR which will be focused on ProtocolError refactor.
  • Loading branch information
muzarski committed Aug 26, 2024
1 parent a67c978 commit fc0b4fe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
29 changes: 16 additions & 13 deletions scylla-cql/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ pub enum QueryError {
#[error(transparent)]
BadQuery(#[from] BadQuery),

/// Failed to deserialize a CQL response from the server.
/// Received a RESULT server response, but failed to deserialize it.
#[error(transparent)]
CqlResponseParseError(#[from] CqlResponseParseError),
CqlResultParseError(#[from] CqlResultParseError),

/// Received an ERROR server response, but failed to deserialize it.
#[error("Failed to deserialize ERROR response: {0}")]
CqlErrorParseError(#[from] CqlErrorParseError),

/// Input/Output error has occurred, connection broken etc.
#[error("IO Error: {0}")]
Expand Down Expand Up @@ -415,9 +419,13 @@ pub enum NewSessionError {
#[error(transparent)]
BadQuery(#[from] BadQuery),

/// Failed to deserialize a CQL response from the server.
/// Received a RESULT server response, but failed to deserialize it.
#[error(transparent)]
CqlResponseParseError(#[from] CqlResponseParseError),
CqlResultParseError(#[from] CqlResultParseError),

/// Received an ERROR server response, but failed to deserialize it.
#[error("Failed to deserialize ERROR response: {0}")]
CqlErrorParseError(#[from] CqlErrorParseError),

/// Input/Output error has occurred, connection broken etc.
#[error("IO Error: {0}")]
Expand Down Expand Up @@ -618,14 +626,8 @@ impl From<UserRequestError> for QueryError {
fn from(value: UserRequestError) -> Self {
match value {
UserRequestError::DbError(err, msg) => QueryError::DbError(err, msg),
UserRequestError::CqlResultParseError(e) => {
// FIXME: change later
CqlResponseParseError::CqlResultParseError(e).into()
}
UserRequestError::CqlErrorParseError(e) => {
// FIXME: change later
CqlResponseParseError::CqlErrorParseError(e).into()
}
UserRequestError::CqlResultParseError(e) => e.into(),
UserRequestError::CqlErrorParseError(e) => e.into(),
UserRequestError::BrokenConnectionError(e) => e.into(),
UserRequestError::UnexpectedResponse => {
// FIXME: make it typed. It needs to wait for ProtocolError refactor.
Expand All @@ -651,7 +653,8 @@ impl From<QueryError> for NewSessionError {
match query_error {
QueryError::DbError(e, msg) => NewSessionError::DbError(e, msg),
QueryError::BadQuery(e) => NewSessionError::BadQuery(e),
QueryError::CqlResponseParseError(e) => NewSessionError::CqlResponseParseError(e),
QueryError::CqlResultParseError(e) => NewSessionError::CqlResultParseError(e),
QueryError::CqlErrorParseError(e) => NewSessionError::CqlErrorParseError(e),
QueryError::IoError(e) => NewSessionError::IoError(e),
QueryError::ProtocolError(m) => NewSessionError::ProtocolError(m),
QueryError::InvalidMessage(m) => NewSessionError::InvalidMessage(m),
Expand Down
3 changes: 2 additions & 1 deletion scylla/src/transport/load_balancing/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2848,7 +2848,8 @@ mod latency_awareness {

// "slow" errors, i.e. ones that are returned after considerable time of query being run
QueryError::DbError(_, _)
| QueryError::CqlResponseParseError(_)
| QueryError::CqlResultParseError(_)
| QueryError::CqlErrorParseError(_)
| QueryError::InvalidMessage(_)
| QueryError::IoError(_)
| QueryError::ProtocolError(_)
Expand Down

0 comments on commit fc0b4fe

Please sign in to comment.