Skip to content

Commit

Permalink
f_errors: CqlResponseParseError
Browse files Browse the repository at this point in the history
  • Loading branch information
muzarski committed Aug 22, 2024
1 parent 3f7a8e0 commit 46d639b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
11 changes: 10 additions & 1 deletion scylla-cql/src/errors.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<std::io::Error>),
Expand Down Expand Up @@ -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<std::io::Error>),
Expand Down Expand Up @@ -482,6 +490,7 @@ 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::IoError(e) => NewSessionError::IoError(e),
QueryError::ProtocolError(m) => NewSessionError::ProtocolError(m),
QueryError::InvalidMessage(m) => NewSessionError::InvalidMessage(m),
Expand Down
35 changes: 21 additions & 14 deletions scylla-cql/src/frame/frame_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")]
Expand All @@ -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)]
Expand Down
6 changes: 4 additions & 2 deletions scylla-cql/src/frame/response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -65,7 +67,7 @@ impl Response {
opcode: ResponseOpcode,
buf: &mut &[u8],
cached_metadata: Option<&ResultMetadata>,
) -> Result<Response, ParseError> {
) -> Result<Response, CqlResponseParseError> {
let response = match opcode {
ResponseOpcode::Error => Response::Error(Error::deserialize(features, buf)?),
ResponseOpcode::Ready => Response::Ready,
Expand Down
1 change: 1 addition & 0 deletions scylla/src/transport/load_balancing/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_)
Expand Down

0 comments on commit 46d639b

Please sign in to comment.