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.

We also enable the `wildcard_enum_match_arm` clippy lint to disallow
using `_` matches.
  • Loading branch information
muzarski committed Oct 14, 2024
1 parent 4ef58f5 commit a360f7a
Show file tree
Hide file tree
Showing 2 changed files with 32 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
27 changes: 27 additions & 0 deletions scylla/src/transport/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,33 @@ pub enum QueryError {
RequestTimeout(String),
}

impl QueryError {
pub(crate) fn is_connection_broken(&self) -> bool {
// Do not remove this lint!
// It's there for a reason - we don't want new variants
// automatically fall under `_` pattern when they are introduced.
#[deny(clippy::wildcard_enum_match_arm)]
match self {
// Error variants that imply that some connection error appeared before/during execution.
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 a360f7a

Please sign in to comment.