From 46d639bd5407c518f94e9a048d2a1472457d0604 Mon Sep 17 00:00:00 2001 From: muzarski Date: Mon, 1 Jul 2024 10:58:52 +0200 Subject: [PATCH] f_errors: CqlResponseParseError --- scylla-cql/src/errors.rs | 11 +++++- scylla-cql/src/frame/frame_errors.rs | 35 +++++++++++-------- scylla-cql/src/frame/response/mod.rs | 6 ++-- .../src/transport/load_balancing/default.rs | 1 + 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/scylla-cql/src/errors.rs b/scylla-cql/src/errors.rs index e884e37ad5..1ebf9cfede 100644 --- a/scylla-cql/src/errors.rs +++ b/scylla-cql/src/errors.rs @@ -1,6 +1,6 @@ //! This module contains various errors which can be returned by `scylla::Session` -use crate::frame::frame_errors::{FrameError, ParseError}; +use crate::frame::frame_errors::{CqlResponseParseError, FrameError, ParseError}; use crate::frame::protocol_features::ProtocolFeatures; use crate::frame::value::SerializeValuesError; use crate::types::serialize::SerializationError; @@ -21,6 +21,10 @@ pub enum QueryError { #[error(transparent)] BadQuery(#[from] BadQuery), + /// Failed to deserialize a CQL response from the server. + #[error(transparent)] + CqlResponseParseError(#[from] CqlResponseParseError), + /// Input/Output error has occurred, connection broken etc. #[error("IO Error: {0}")] IoError(Arc), @@ -381,6 +385,10 @@ pub enum NewSessionError { #[error(transparent)] BadQuery(#[from] BadQuery), + /// Failed to deserialize a CQL response from the server. + #[error(transparent)] + CqlResponseParseError(#[from] CqlResponseParseError), + /// Input/Output error has occurred, connection broken etc. #[error("IO Error: {0}")] IoError(Arc), @@ -482,6 +490,7 @@ impl From 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::IoError(e) => NewSessionError::IoError(e), QueryError::ProtocolError(m) => NewSessionError::ProtocolError(m), QueryError::InvalidMessage(m) => NewSessionError::InvalidMessage(m), diff --git a/scylla-cql/src/frame/frame_errors.rs b/scylla-cql/src/frame/frame_errors.rs index 2edf8bcc7a..b90eef3a79 100644 --- a/scylla-cql/src/frame/frame_errors.rs +++ b/scylla-cql/src/frame/frame_errors.rs @@ -37,20 +37,6 @@ pub enum FrameError { #[derive(Error, Debug)] pub enum ParseError { - #[error(transparent)] - CqlErrorParseError(#[from] CqlErrorParseError), - #[error(transparent)] - CqlAuthChallengeParseError(#[from] CqlAuthChallengeParseError), - #[error(transparent)] - CqlAuthSuccessParseError(#[from] CqlAuthSuccessParseError), - #[error(transparent)] - CqlAuthenticateParseError(#[from] CqlAuthenticateParseError), - #[error(transparent)] - CqlSupportedParseError(#[from] CqlSupportedParseError), - #[error(transparent)] - CqlEventParseError(#[from] CqlEventParseError), - #[error(transparent)] - CqlResultParseError(#[from] CqlResultParseError), #[error("Low-level deserialization failed: {0}")] LowLevelDeserializationError(#[from] LowLevelDeserializationError), #[error("Could not serialize frame: {0}")] @@ -69,6 +55,27 @@ pub enum ParseError { CqlTypeError(#[from] CqlTypeError), } +/// An error type returned when deserialization of CQL +/// server response fails. +#[non_exhaustive] +#[derive(Error, Debug, Clone)] +pub enum CqlResponseParseError { + #[error("Failed to deserialize ERROR response: {0}")] + CqlErrorParseError(#[from] CqlErrorParseError), + #[error("Failed to deserialize AUTH_CHALLENGE response: {0}")] + CqlAuthChallengeParseError(#[from] CqlAuthChallengeParseError), + #[error("Failed to deserialize AUTH_SUCCESS response: {0}")] + CqlAuthSuccessParseError(#[from] CqlAuthSuccessParseError), + #[error("Failed to deserialize AUTHENTICATE response: {0}")] + CqlAuthenticateParseError(#[from] CqlAuthenticateParseError), + #[error("Failed to deserialize SUPPORTED response: {0}")] + CqlSupportedParseError(#[from] CqlSupportedParseError), + #[error("Failed to deserialize EVENT response: {0}")] + CqlEventParseError(#[from] CqlEventParseError), + #[error(transparent)] + CqlResultParseError(#[from] CqlResultParseError), +} + /// An error type returned when deserialization of ERROR response fails. #[non_exhaustive] #[derive(Error, Debug, Clone)] diff --git a/scylla-cql/src/frame/response/mod.rs b/scylla-cql/src/frame/response/mod.rs index 569a14f401..8e6e7ff335 100644 --- a/scylla-cql/src/frame/response/mod.rs +++ b/scylla-cql/src/frame/response/mod.rs @@ -8,10 +8,12 @@ pub mod supported; pub use error::Error; pub use supported::Supported; +use crate::errors::QueryError; use crate::frame::protocol_features::ProtocolFeatures; use crate::frame::response::result::ResultMetadata; use crate::frame::TryFromPrimitiveError; -use crate::{errors::QueryError, frame::frame_errors::ParseError}; + +use super::frame_errors::CqlResponseParseError; #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] #[repr(u8)] @@ -65,7 +67,7 @@ impl Response { opcode: ResponseOpcode, buf: &mut &[u8], cached_metadata: Option<&ResultMetadata>, - ) -> Result { + ) -> Result { let response = match opcode { ResponseOpcode::Error => Response::Error(Error::deserialize(features, buf)?), ResponseOpcode::Ready => Response::Ready, diff --git a/scylla/src/transport/load_balancing/default.rs b/scylla/src/transport/load_balancing/default.rs index 46aa282992..519edf5869 100644 --- a/scylla/src/transport/load_balancing/default.rs +++ b/scylla/src/transport/load_balancing/default.rs @@ -2689,6 +2689,7 @@ mod latency_awareness { // "slow" errors, i.e. ones that are returned after considerable time of query being run QueryError::DbError(_, _) + | QueryError::CqlResponseParseError(_) | QueryError::InvalidMessage(_) | QueryError::IoError(_) | QueryError::ProtocolError(_)