diff --git a/scylla-cql/src/frame/value.rs b/scylla-cql/src/frame/value.rs index 0db6f503a..036511e4e 100644 --- a/scylla-cql/src/frame/value.rs +++ b/scylla-cql/src/frame/value.rs @@ -12,31 +12,10 @@ use super::response::result::CqlValue; use super::types::vint_encode; use super::types::RawValue; -#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] -#[error("Value too big to be sent in a request - max 2GiB allowed")] -#[deprecated( - since = "0.15.1", - note = "Legacy serialization API is not type-safe and is going to be removed soon" -)] -pub struct ValueTooBig; - #[derive(Debug, Error, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] #[error("Value is too large to fit in the CQL type")] pub struct ValueOverflow; -#[allow(deprecated)] -#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] -pub enum SerializeValuesError { - #[error("Too many values to add, max 65,535 values can be sent in a request")] - TooManyValues, - #[error("Mixing named and not named values is not allowed")] - MixingNamedAndNotNamedValues, - #[error(transparent)] - ValueTooBig(#[from] ValueTooBig), - #[error("Parsing serialized values failed")] - ParseError, -} - /// Represents an unset value #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct Unset; @@ -684,6 +663,22 @@ mod legacy { fn serialize(&self, buf: &mut Vec) -> Result<(), ValueTooBig>; } + #[derive(Debug, Error, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] + #[error("Value too big to be sent in a request - max 2GiB allowed")] + pub struct ValueTooBig; + + #[derive(Debug, Error, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] + pub enum SerializeValuesError { + #[error("Too many values to add, max 65,535 values can be sent in a request")] + TooManyValues, + #[error("Mixing named and not named values is not allowed")] + MixingNamedAndNotNamedValues, + #[error(transparent)] + ValueTooBig(#[from] ValueTooBig), + #[error("Parsing serialized values failed")] + ParseError, + } + /// Keeps a buffer with serialized Values /// Allows adding new Values and iterating over serialized ones #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] @@ -1887,5 +1882,6 @@ mod legacy { pub use legacy::{ LegacyBatchValues, LegacyBatchValuesFirstSerialized, LegacyBatchValuesFromIter, LegacyBatchValuesIterator, LegacyBatchValuesIteratorFromIterator, LegacySerializedValues, - LegacySerializedValuesIterator, SerializedResult, TupleValuesIter, Value, ValueList, + LegacySerializedValuesIterator, SerializeValuesError, SerializedResult, TupleValuesIter, Value, + ValueList, ValueTooBig, }; diff --git a/scylla-cql/src/types/serialize/mod.rs b/scylla-cql/src/types/serialize/mod.rs index 3bc3424dc..8d63e3204 100644 --- a/scylla-cql/src/types/serialize/mod.rs +++ b/scylla-cql/src/types/serialize/mod.rs @@ -32,6 +32,8 @@ pub use writers::{CellValueBuilder, CellWriter, RowWriter}; /// a list of named values encoded with the legacy `ValueList` trait is passed /// as an argument to the statement, and rewriting it using the new /// `SerializeRow` interface fails. +// TODO: remove mentions about legacy errors from the above description when +// they are removed. #[derive(Debug, Clone, Error)] #[error("SerializationError: {0}")] pub struct SerializationError(Arc); diff --git a/scylla-cql/src/types/serialize/row.rs b/scylla-cql/src/types/serialize/row.rs index 7478a0b9c..cf05398fd 100644 --- a/scylla-cql/src/types/serialize/row.rs +++ b/scylla-cql/src/types/serialize/row.rs @@ -17,7 +17,7 @@ use crate::frame::response::result::ColumnType; use crate::frame::response::result::PreparedMetadata; use crate::frame::types; #[allow(deprecated)] -use crate::frame::value::{LegacySerializedValues, SerializeValuesError, ValueList}; +use crate::frame::value::{LegacySerializedValues, ValueList}; use crate::frame::{response::result::ColumnSpec, types::RawValue}; use super::value::SerializeValue; @@ -687,6 +687,8 @@ pub enum BuiltinSerializationErrorKind { /// The error that caused the column serialization to fail. err: SerializationError, }, + /// Too many values to add, max 65,535 values can be sent in a request. + TooManyValues, } impl Display for BuiltinSerializationErrorKind { @@ -695,6 +697,12 @@ impl Display for BuiltinSerializationErrorKind { BuiltinSerializationErrorKind::ColumnSerializationFailed { name, err } => { write!(f, "failed to serialize column {name}: {err}") } + BuiltinSerializationErrorKind::TooManyValues => { + write!( + f, + "Too many values to add, max 65,535 values can be sent in a request" + ) + } } } } @@ -771,9 +779,9 @@ impl SerializedValues { let element_count = match writer.value_count().try_into() { Ok(n) => n, Err(_) => { - return Err(SerializationError(Arc::new( - SerializeValuesError::TooManyValues, - ))) + return Err(SerializationError(Arc::new(mk_ser_err::( + BuiltinSerializationErrorKind::TooManyValues, + )))); } }; @@ -829,9 +837,9 @@ impl SerializedValues { typ: &ColumnType, ) -> Result<(), SerializationError> { if self.element_count() == u16::MAX { - return Err(SerializationError(Arc::new( - SerializeValuesError::TooManyValues, - ))); + return Err(SerializationError(Arc::new(mk_ser_err::( + BuiltinSerializationErrorKind::TooManyValues, + )))); } let len_before_serialize: usize = self.serialized_values.len(); @@ -1158,7 +1166,10 @@ pub(crate) mod tests { let err = do_serialize_err(v, &spec); let err = get_ser_err(&err); assert_eq!(err.rust_name, std::any::type_name::<(&str, i32)>()); - let BuiltinSerializationErrorKind::ColumnSerializationFailed { name, err: _ } = &err.kind; + let BuiltinSerializationErrorKind::ColumnSerializationFailed { name, err: _ } = &err.kind + else { + panic!("Expected BuiltinSerializationErrorKind::ColumnSerializationFailed") + }; assert_eq!(name, "b"); } @@ -1185,7 +1196,10 @@ pub(crate) mod tests { let err = do_serialize_err(v, &spec); let err = get_ser_err(&err); assert_eq!(err.rust_name, std::any::type_name::>()); - let BuiltinSerializationErrorKind::ColumnSerializationFailed { name, err: _ } = &err.kind; + let BuiltinSerializationErrorKind::ColumnSerializationFailed { name, err: _ } = &err.kind + else { + panic!("Expected BuiltinSerializationErrorKind::ColumnSerializationFailed") + }; assert_eq!(name, "b"); } @@ -1219,7 +1233,10 @@ pub(crate) mod tests { let err = do_serialize_err(v, &spec); let err = get_ser_err(&err); assert_eq!(err.rust_name, std::any::type_name::>()); - let BuiltinSerializationErrorKind::ColumnSerializationFailed { name, err: _ } = &err.kind; + let BuiltinSerializationErrorKind::ColumnSerializationFailed { name, err: _ } = &err.kind + else { + panic!("Expected BuiltinSerializationErrorKind::ColumnSerializationFailed") + }; assert_eq!(name, "b"); } diff --git a/scylla/src/transport/errors.rs b/scylla/src/transport/errors.rs index 7d835f269..fdd5b9aa0 100644 --- a/scylla/src/transport/errors.rs +++ b/scylla/src/transport/errors.rs @@ -12,6 +12,7 @@ use std::{ sync::Arc, }; +#[allow(deprecated)] use scylla_cql::{ frame::{ frame_errors::{ @@ -124,6 +125,7 @@ pub enum QueryError { IntoLegacyQueryResultError(#[from] IntoLegacyQueryResultError), } +#[allow(deprecated)] impl From for QueryError { fn from(serialized_err: SerializeValuesError) -> QueryError { QueryError::BadQuery(BadQuery::SerializeValuesError(serialized_err)) @@ -573,7 +575,12 @@ pub enum ViewsMetadataError { #[non_exhaustive] pub enum BadQuery { /// Failed to serialize values passed to a query - values too big + #[deprecated( + since = "0.15.1", + note = "Legacy serialization API is not type-safe and is going to be removed soon" + )] #[error("Serializing values failed: {0} ")] + #[allow(deprecated)] SerializeValuesError(#[from] SerializeValuesError), #[error("Serializing values failed: {0} ")]