Skip to content
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: refactor error types on a connection level #1067

Merged
merged 33 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a5bb6f2
conn_pool: narrow return error type to io::Error
muzarski Aug 20, 2024
46c26a9
connection: increase log level to error for non-event response
muzarski Aug 22, 2024
215ada4
errors: introduce CqlResponseKind
muzarski Sep 17, 2024
78f3073
response: get response kind from response and resp parse errors
muzarski Sep 17, 2024
dd6d32f
errors: BrokenConnectionError
muzarski Aug 20, 2024
632c765
errors: CqlEventHandlingError
muzarski Aug 22, 2024
a56a9b0
errors: ResponseParseError
muzarski Aug 22, 2024
8347bad
conn: transform errors in handle_event
muzarski Aug 22, 2024
c89db3c
errors: RequestError
muzarski Aug 21, 2024
8381692
connection: introduce ConnectionError
muzarski Aug 21, 2024
264fe78
connection: include BrokenConnectionError in ConnectionError
muzarski Aug 21, 2024
939d6f2
errors: remove TranslationError from Query/NewSessionError
muzarski Aug 21, 2024
3396efa
errors: remove QueryError::is_address_available_for_use
muzarski Aug 21, 2024
076330a
conn: move ssl check below options extraction
muzarski Aug 21, 2024
bd81495
errors: CqlRequestErrorKind
muzarski Sep 17, 2024
3529b6e
conn: introduce ConnectionSetupRequestError
muzarski Aug 21, 2024
bf46f01
conn: adjust startup request logic
muzarski Aug 21, 2024
fd694da
conn: handle errors in register
muzarski Aug 21, 2024
0ef7cc2
conn: handle errors during authentication
muzarski Aug 21, 2024
c7eacd6
conn: remove QueryError from ConnectionError
muzarski Aug 21, 2024
026b251
errors: introduce UserRequestError
muzarski Aug 22, 2024
f3240a6
errors: From<RequestError> for UserRequestError
muzarski Aug 26, 2024
f8eb4ab
connection: return UserRequestError in connection::prepare
muzarski Aug 26, 2024
ac44d84
connection: narrow error return type of Connection::reprepare
muzarski Aug 26, 2024
da48224
conn: narrow return type for execute and query
muzarski Aug 26, 2024
e9078cf
non_error_response: narrow return type
muzarski Aug 26, 2024
1128cd4
conn: map sub-error type to UserRequestError
muzarski Aug 26, 2024
0d0d267
errors: remove From<RequestError> for QueryError
muzarski Aug 26, 2024
09b06fc
errors: replace CqlResponseParseError variant in QueryError
muzarski Aug 26, 2024
b242c60
conn: make ConnectionError clonable
muzarski Aug 29, 2024
8e48c50
node: ConnectionPoolError
muzarski Aug 28, 2024
885115b
error: remove From<std::io::Error> for QueryError
muzarski Aug 29, 2024
9259dea
f_errors: Enrich CqlResultParseError messages with response kind
muzarski Aug 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
421 changes: 384 additions & 37 deletions scylla-cql/src/errors.rs

Large diffs are not rendered by default.

23 changes: 19 additions & 4 deletions scylla-cql/src/frame/frame_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::sync::Arc;

use super::TryFromPrimitiveError;
use crate::cql_to_rust::CqlTypeError;
use crate::errors::CqlResponseKind;
use crate::frame::value::SerializeValuesError;
use crate::types::deserialize::{DeserializationError, TypeCheckError};
use crate::types::serialize::SerializationError;
Expand Down Expand Up @@ -78,6 +79,20 @@ pub enum CqlResponseParseError {
CqlResultParseError(#[from] CqlResultParseError),
}

impl CqlResponseParseError {
pub fn to_response_kind(&self) -> CqlResponseKind {
match self {
CqlResponseParseError::CqlErrorParseError(_) => CqlResponseKind::Error,
CqlResponseParseError::CqlAuthChallengeParseError(_) => CqlResponseKind::AuthChallenge,
CqlResponseParseError::CqlAuthSuccessParseError(_) => CqlResponseKind::AuthSuccess,
CqlResponseParseError::CqlAuthenticateParseError(_) => CqlResponseKind::Authenticate,
CqlResponseParseError::CqlSupportedParseError(_) => CqlResponseKind::Supported,
CqlResponseParseError::CqlEventParseError(_) => CqlResponseKind::Event,
CqlResponseParseError::CqlResultParseError(_) => CqlResponseKind::Result,
}
}
}

/// An error type returned when deserialization of ERROR response fails.
#[non_exhaustive]
#[derive(Error, Debug, Clone)]
Expand Down Expand Up @@ -134,15 +149,15 @@ pub enum CqlResultParseError {
ResultIdParseError(LowLevelDeserializationError),
#[error("Unknown RESULT response id: {0}")]
UnknownResultId(i32),
#[error("'Set_keyspace' response deserialization failed: {0}")]
#[error("RESULT:Set_keyspace response deserialization failed: {0}")]
SetKeyspaceParseError(#[from] SetKeyspaceParseError),
// This is an error returned during deserialization of
// `RESULT::Schema_change` response, and not `EVENT` response.
#[error("'Schema_change' response deserialization failed: {0}")]
#[error("RESULT:Schema_change response deserialization failed: {0}")]
SchemaChangeParseError(#[from] SchemaChangeEventParseError),
#[error("'Prepared' response deserialization failed: {0}")]
#[error("RESULT:Prepared response deserialization failed: {0}")]
PreparedParseError(#[from] PreparedParseError),
#[error("'Rows' response deserialization failed: {0}")]
#[error("RESULT:Rows response deserialization failed: {0}")]
RowsParseError(#[from] RowsParseError),
}

Expand Down
41 changes: 36 additions & 5 deletions scylla-cql/src/frame/response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::sync::Arc;
pub use error::Error;
pub use supported::Supported;

use crate::errors::QueryError;
use crate::errors::{CqlResponseKind, UserRequestError};
use crate::frame::protocol_features::ProtocolFeatures;
use crate::frame::response::result::ResultMetadata;
use crate::frame::TryFromPrimitiveError;
Expand Down Expand Up @@ -64,6 +64,19 @@ pub enum Response {
}

impl Response {
pub fn to_response_kind(&self) -> CqlResponseKind {
match self {
Response::Error(_) => CqlResponseKind::Error,
Response::Ready => CqlResponseKind::Ready,
Response::Result(_) => CqlResponseKind::Result,
Response::Authenticate(_) => CqlResponseKind::Authenticate,
Response::AuthSuccess(_) => CqlResponseKind::AuthSuccess,
Response::AuthChallenge(_) => CqlResponseKind::AuthChallenge,
Response::Supported(_) => CqlResponseKind::Supported,
Response::Event(_) => CqlResponseKind::Event,
}
}

pub fn deserialize(
features: &ProtocolFeatures,
opcode: ResponseOpcode,
Expand Down Expand Up @@ -93,17 +106,21 @@ impl Response {
Ok(response)
}

pub fn into_non_error_response(self) -> Result<NonErrorResponse, QueryError> {
Ok(match self {
Response::Error(err) => return Err(QueryError::from(err)),
pub fn into_non_error_response(self) -> Result<NonErrorResponse, UserRequestError> {
let non_error_response = match self {
Response::Error(error::Error { error, reason }) => {
return Err(UserRequestError::DbError(error, reason))
}
Response::Ready => NonErrorResponse::Ready,
Response::Result(res) => NonErrorResponse::Result(res),
Response::Authenticate(auth) => NonErrorResponse::Authenticate(auth),
Response::AuthSuccess(auth_succ) => NonErrorResponse::AuthSuccess(auth_succ),
Response::AuthChallenge(auth_chal) => NonErrorResponse::AuthChallenge(auth_chal),
Response::Supported(sup) => NonErrorResponse::Supported(sup),
Response::Event(eve) => NonErrorResponse::Event(eve),
})
};

Ok(non_error_response)
}
}

Expand All @@ -118,3 +135,17 @@ pub enum NonErrorResponse {
Supported(Supported),
Event(event::Event),
}

impl NonErrorResponse {
pub fn to_response_kind(&self) -> CqlResponseKind {
match self {
NonErrorResponse::Ready => CqlResponseKind::Ready,
NonErrorResponse::Result(_) => CqlResponseKind::Result,
NonErrorResponse::Authenticate(_) => CqlResponseKind::Authenticate,
NonErrorResponse::AuthSuccess(_) => CqlResponseKind::AuthSuccess,
NonErrorResponse::AuthChallenge(_) => CqlResponseKind::AuthChallenge,
NonErrorResponse::Supported(_) => CqlResponseKind::Supported,
NonErrorResponse::Event(_) => CqlResponseKind::Event,
}
}
}
Loading
Loading