Skip to content

Commit 9093ca9

Browse files
committed
f_errors: CqlResponseParseError
1 parent 33a629b commit 9093ca9

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

scylla-cql/src/errors.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! This module contains various errors which can be returned by `scylla::Session`
22
3-
use crate::frame::frame_errors::{FrameError, ParseError};
3+
use crate::frame::frame_errors::{CqlResponseParseError, FrameError, ParseError};
44
use crate::frame::protocol_features::ProtocolFeatures;
55
use crate::frame::value::SerializeValuesError;
66
use crate::types::serialize::SerializationError;
@@ -21,6 +21,10 @@ pub enum QueryError {
2121
#[error(transparent)]
2222
BadQuery(#[from] BadQuery),
2323

24+
/// Failed to deserialize a CQL response from the server.
25+
#[error(transparent)]
26+
CqlResponseParseError(#[from] CqlResponseParseError),
27+
2428
/// Input/Output error has occurred, connection broken etc.
2529
#[error("IO Error: {0}")]
2630
IoError(Arc<std::io::Error>),
@@ -381,6 +385,10 @@ pub enum NewSessionError {
381385
#[error(transparent)]
382386
BadQuery(#[from] BadQuery),
383387

388+
/// Failed to deserialize a CQL response from the server.
389+
#[error(transparent)]
390+
CqlResponseParseError(#[from] CqlResponseParseError),
391+
384392
/// Input/Output error has occurred, connection broken etc.
385393
#[error("IO Error: {0}")]
386394
IoError(Arc<std::io::Error>),
@@ -482,6 +490,7 @@ impl From<QueryError> for NewSessionError {
482490
match query_error {
483491
QueryError::DbError(e, msg) => NewSessionError::DbError(e, msg),
484492
QueryError::BadQuery(e) => NewSessionError::BadQuery(e),
493+
QueryError::CqlResponseParseError(e) => NewSessionError::CqlResponseParseError(e),
485494
QueryError::IoError(e) => NewSessionError::IoError(e),
486495
QueryError::ProtocolError(m) => NewSessionError::ProtocolError(m),
487496
QueryError::InvalidMessage(m) => NewSessionError::InvalidMessage(m),

scylla-cql/src/frame/frame_errors.rs

+21-14
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,6 @@ pub enum FrameError {
3737

3838
#[derive(Error, Debug)]
3939
pub enum ParseError {
40-
#[error(transparent)]
41-
CqlErrorParseError(#[from] CqlErrorParseError),
42-
#[error(transparent)]
43-
CqlAuthChallengeParseError(#[from] CqlAuthChallengeParseError),
44-
#[error(transparent)]
45-
CqlAuthSuccessParseError(#[from] CqlAuthSuccessParseError),
46-
#[error(transparent)]
47-
CqlAuthenticateParseError(#[from] CqlAuthenticateParseError),
48-
#[error(transparent)]
49-
CqlSupportedParseError(#[from] CqlSupportedParseError),
50-
#[error(transparent)]
51-
CqlEventParseError(#[from] CqlEventParseError),
52-
#[error(transparent)]
53-
CqlResultParseError(#[from] CqlResultParseError),
5440
#[error("Low-level deserialization failed: {0}")]
5541
LowLevelDeserializationError(#[from] LowLevelDeserializationError),
5642
#[error("Could not serialize frame: {0}")]
@@ -69,6 +55,27 @@ pub enum ParseError {
6955
CqlTypeError(#[from] CqlTypeError),
7056
}
7157

58+
/// An error type returned when deserialization of CQL
59+
/// server response fails.
60+
#[non_exhaustive]
61+
#[derive(Error, Debug, Clone)]
62+
pub enum CqlResponseParseError {
63+
#[error("Failed to deserialize ERROR response: {0}")]
64+
CqlErrorParseError(#[from] CqlErrorParseError),
65+
#[error("Failed to deserialize AUTH_CHALLENGE response: {0}")]
66+
CqlAuthChallengeParseError(#[from] CqlAuthChallengeParseError),
67+
#[error("Failed to deserialize AUTH_SUCCESS response: {0}")]
68+
CqlAuthSuccessParseError(#[from] CqlAuthSuccessParseError),
69+
#[error("Failed to deserialize AUTHENTICATE response: {0}")]
70+
CqlAuthenticateParseError(#[from] CqlAuthenticateParseError),
71+
#[error("Failed to deserialize SUPPORTED response: {0}")]
72+
CqlSupportedParseError(#[from] CqlSupportedParseError),
73+
#[error("Failed to deserialize EVENT response: {0}")]
74+
CqlEventParseError(#[from] CqlEventParseError),
75+
#[error(transparent)]
76+
CqlResultParseError(#[from] CqlResultParseError),
77+
}
78+
7279
/// An error type returned when deserialization of ERROR response fails.
7380
#[non_exhaustive]
7481
#[derive(Error, Debug, Clone)]

scylla-cql/src/frame/response/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ pub mod supported;
88
pub use error::Error;
99
pub use supported::Supported;
1010

11+
use crate::errors::QueryError;
1112
use crate::frame::protocol_features::ProtocolFeatures;
1213
use crate::frame::response::result::ResultMetadata;
1314
use crate::frame::TryFromPrimitiveError;
14-
use crate::{errors::QueryError, frame::frame_errors::ParseError};
15+
16+
use super::frame_errors::CqlResponseParseError;
1517

1618
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
1719
#[repr(u8)]
@@ -65,7 +67,7 @@ impl Response {
6567
opcode: ResponseOpcode,
6668
buf: &mut &[u8],
6769
cached_metadata: Option<&ResultMetadata>,
68-
) -> Result<Response, ParseError> {
70+
) -> Result<Response, CqlResponseParseError> {
6971
let response = match opcode {
7072
ResponseOpcode::Error => Response::Error(Error::deserialize(features, buf)?),
7173
ResponseOpcode::Ready => Response::Ready,

scylla/src/transport/load_balancing/default.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2689,6 +2689,7 @@ mod latency_awareness {
26892689

26902690
// "slow" errors, i.e. ones that are returned after considerable time of query being run
26912691
QueryError::DbError(_, _)
2692+
| QueryError::CqlResponseParseError(_)
26922693
| QueryError::InvalidMessage(_)
26932694
| QueryError::IoError(_)
26942695
| QueryError::ProtocolError(_)

0 commit comments

Comments
 (0)