Skip to content

Commit

Permalink
use_keyspace: don't use wildcard '_' in QueryError match
Browse files Browse the repository at this point in the history
Since last time, during error refactor I introduced a silent
bug to the code (scylladb#1075),
I'd like to prevent that from happening in the future. This is why
we replace a `_` match with explicit error variants when deciding
if error received after `USE KEYSPACE` should be ignored.
  • Loading branch information
muzarski committed Oct 4, 2024
1 parent 98204a1 commit f263046
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
9 changes: 5 additions & 4 deletions scylla/src/transport/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,12 +784,13 @@ pub(crate) fn use_keyspace_result(
for result in use_keyspace_results {
match result {
Ok(()) => was_ok = true,
Err(err) => match err {
QueryError::BrokenConnection(_) | QueryError::ConnectionPoolError(_) => {
Err(err) => {
if err.is_connection_broken() {
broken_conn_error = Some(err)
} else {
return Err(err);
}
_ => return Err(err),
},
}
}
}

Expand Down
23 changes: 23 additions & 0 deletions scylla/src/transport/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,29 @@ pub enum QueryError {
RequestTimeout(String),
}

impl QueryError {
pub(crate) fn is_connection_broken(&self) -> bool {
match self {
// Error variants that imply that some connection error appeared before/during exeuction.
QueryError::BrokenConnection(_) | QueryError::ConnectionPoolError(_) => true,

// Other errors.
QueryError::DbError(_, _)
| QueryError::BadQuery(_)
| QueryError::CqlRequestSerialization(_)
| QueryError::BodyExtensionsParseError(_)
| QueryError::EmptyPlan
| QueryError::CqlResultParseError(_)
| QueryError::CqlErrorParseError(_)
| QueryError::MetadataError(_)
| QueryError::ProtocolError(_)
| QueryError::TimeoutError
| QueryError::UnableToAllocStreamId
| QueryError::RequestTimeout(_) => false,
}
}
}

impl From<SerializeValuesError> for QueryError {
fn from(serialized_err: SerializeValuesError) -> QueryError {
QueryError::BadQuery(BadQuery::SerializeValuesError(serialized_err))
Expand Down

0 comments on commit f263046

Please sign in to comment.