Skip to content

Commit 3d4dd69

Browse files
authored
Merge pull request #1149 from wprzytula/remove-uses-of-serialize-values-error
Remove uses of `SerializeValuesError` and deprecate it
2 parents 868d86f + 59eb5c1 commit 3d4dd69

File tree

4 files changed

+54
-32
lines changed

4 files changed

+54
-32
lines changed

scylla-cql/src/frame/value.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,10 @@ use super::response::result::CqlValue;
1212
use super::types::vint_encode;
1313
use super::types::RawValue;
1414

15-
#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
16-
#[error("Value too big to be sent in a request - max 2GiB allowed")]
17-
#[deprecated(
18-
since = "0.15.1",
19-
note = "Legacy serialization API is not type-safe and is going to be removed soon"
20-
)]
21-
pub struct ValueTooBig;
22-
2315
#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
2416
#[error("Value is too large to fit in the CQL type")]
2517
pub struct ValueOverflow;
2618

27-
#[allow(deprecated)]
28-
#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
29-
pub enum SerializeValuesError {
30-
#[error("Too many values to add, max 65,535 values can be sent in a request")]
31-
TooManyValues,
32-
#[error("Mixing named and not named values is not allowed")]
33-
MixingNamedAndNotNamedValues,
34-
#[error(transparent)]
35-
ValueTooBig(#[from] ValueTooBig),
36-
#[error("Parsing serialized values failed")]
37-
ParseError,
38-
}
39-
4019
/// Represents an unset value
4120
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
4221
pub struct Unset;
@@ -684,6 +663,22 @@ mod legacy {
684663
fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), ValueTooBig>;
685664
}
686665

666+
#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
667+
#[error("Value too big to be sent in a request - max 2GiB allowed")]
668+
pub struct ValueTooBig;
669+
670+
#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
671+
pub enum SerializeValuesError {
672+
#[error("Too many values to add, max 65,535 values can be sent in a request")]
673+
TooManyValues,
674+
#[error("Mixing named and not named values is not allowed")]
675+
MixingNamedAndNotNamedValues,
676+
#[error(transparent)]
677+
ValueTooBig(#[from] ValueTooBig),
678+
#[error("Parsing serialized values failed")]
679+
ParseError,
680+
}
681+
687682
/// Keeps a buffer with serialized Values
688683
/// Allows adding new Values and iterating over serialized ones
689684
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
@@ -1887,5 +1882,6 @@ mod legacy {
18871882
pub use legacy::{
18881883
LegacyBatchValues, LegacyBatchValuesFirstSerialized, LegacyBatchValuesFromIter,
18891884
LegacyBatchValuesIterator, LegacyBatchValuesIteratorFromIterator, LegacySerializedValues,
1890-
LegacySerializedValuesIterator, SerializedResult, TupleValuesIter, Value, ValueList,
1885+
LegacySerializedValuesIterator, SerializeValuesError, SerializedResult, TupleValuesIter, Value,
1886+
ValueList, ValueTooBig,
18911887
};

scylla-cql/src/types/serialize/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ pub use writers::{CellValueBuilder, CellWriter, RowWriter};
3232
/// a list of named values encoded with the legacy `ValueList` trait is passed
3333
/// as an argument to the statement, and rewriting it using the new
3434
/// `SerializeRow` interface fails.
35+
// TODO: remove mentions about legacy errors from the above description when
36+
// they are removed.
3537
#[derive(Debug, Clone, Error)]
3638
#[error("SerializationError: {0}")]
3739
pub struct SerializationError(Arc<dyn Error + Send + Sync>);

scylla-cql/src/types/serialize/row.rs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::frame::response::result::ColumnType;
1717
use crate::frame::response::result::PreparedMetadata;
1818
use crate::frame::types;
1919
#[allow(deprecated)]
20-
use crate::frame::value::{LegacySerializedValues, SerializeValuesError, ValueList};
20+
use crate::frame::value::{LegacySerializedValues, ValueList};
2121
use crate::frame::{response::result::ColumnSpec, types::RawValue};
2222

2323
use super::value::SerializeValue;
@@ -687,6 +687,8 @@ pub enum BuiltinSerializationErrorKind {
687687
/// The error that caused the column serialization to fail.
688688
err: SerializationError,
689689
},
690+
/// Too many values to add, max 65,535 values can be sent in a request.
691+
TooManyValues,
690692
}
691693

692694
impl Display for BuiltinSerializationErrorKind {
@@ -695,6 +697,12 @@ impl Display for BuiltinSerializationErrorKind {
695697
BuiltinSerializationErrorKind::ColumnSerializationFailed { name, err } => {
696698
write!(f, "failed to serialize column {name}: {err}")
697699
}
700+
BuiltinSerializationErrorKind::TooManyValues => {
701+
write!(
702+
f,
703+
"Too many values to add, max 65,535 values can be sent in a request"
704+
)
705+
}
698706
}
699707
}
700708
}
@@ -771,9 +779,9 @@ impl SerializedValues {
771779
let element_count = match writer.value_count().try_into() {
772780
Ok(n) => n,
773781
Err(_) => {
774-
return Err(SerializationError(Arc::new(
775-
SerializeValuesError::TooManyValues,
776-
)))
782+
return Err(SerializationError(Arc::new(mk_ser_err::<Self>(
783+
BuiltinSerializationErrorKind::TooManyValues,
784+
))));
777785
}
778786
};
779787

@@ -829,9 +837,9 @@ impl SerializedValues {
829837
typ: &ColumnType,
830838
) -> Result<(), SerializationError> {
831839
if self.element_count() == u16::MAX {
832-
return Err(SerializationError(Arc::new(
833-
SerializeValuesError::TooManyValues,
834-
)));
840+
return Err(SerializationError(Arc::new(mk_ser_err::<Self>(
841+
BuiltinSerializationErrorKind::TooManyValues,
842+
))));
835843
}
836844

837845
let len_before_serialize: usize = self.serialized_values.len();
@@ -1158,7 +1166,10 @@ pub(crate) mod tests {
11581166
let err = do_serialize_err(v, &spec);
11591167
let err = get_ser_err(&err);
11601168
assert_eq!(err.rust_name, std::any::type_name::<(&str, i32)>());
1161-
let BuiltinSerializationErrorKind::ColumnSerializationFailed { name, err: _ } = &err.kind;
1169+
let BuiltinSerializationErrorKind::ColumnSerializationFailed { name, err: _ } = &err.kind
1170+
else {
1171+
panic!("Expected BuiltinSerializationErrorKind::ColumnSerializationFailed")
1172+
};
11621173
assert_eq!(name, "b");
11631174
}
11641175

@@ -1185,7 +1196,10 @@ pub(crate) mod tests {
11851196
let err = do_serialize_err(v, &spec);
11861197
let err = get_ser_err(&err);
11871198
assert_eq!(err.rust_name, std::any::type_name::<Vec<&str>>());
1188-
let BuiltinSerializationErrorKind::ColumnSerializationFailed { name, err: _ } = &err.kind;
1199+
let BuiltinSerializationErrorKind::ColumnSerializationFailed { name, err: _ } = &err.kind
1200+
else {
1201+
panic!("Expected BuiltinSerializationErrorKind::ColumnSerializationFailed")
1202+
};
11891203
assert_eq!(name, "b");
11901204
}
11911205

@@ -1219,7 +1233,10 @@ pub(crate) mod tests {
12191233
let err = do_serialize_err(v, &spec);
12201234
let err = get_ser_err(&err);
12211235
assert_eq!(err.rust_name, std::any::type_name::<BTreeMap<&str, i32>>());
1222-
let BuiltinSerializationErrorKind::ColumnSerializationFailed { name, err: _ } = &err.kind;
1236+
let BuiltinSerializationErrorKind::ColumnSerializationFailed { name, err: _ } = &err.kind
1237+
else {
1238+
panic!("Expected BuiltinSerializationErrorKind::ColumnSerializationFailed")
1239+
};
12231240
assert_eq!(name, "b");
12241241
}
12251242

scylla/src/transport/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::{
1212
sync::Arc,
1313
};
1414

15+
#[allow(deprecated)]
1516
use scylla_cql::{
1617
frame::{
1718
frame_errors::{
@@ -124,6 +125,7 @@ pub enum QueryError {
124125
IntoLegacyQueryResultError(#[from] IntoLegacyQueryResultError),
125126
}
126127

128+
#[allow(deprecated)]
127129
impl From<SerializeValuesError> for QueryError {
128130
fn from(serialized_err: SerializeValuesError) -> QueryError {
129131
QueryError::BadQuery(BadQuery::SerializeValuesError(serialized_err))
@@ -573,7 +575,12 @@ pub enum ViewsMetadataError {
573575
#[non_exhaustive]
574576
pub enum BadQuery {
575577
/// Failed to serialize values passed to a query - values too big
578+
#[deprecated(
579+
since = "0.15.1",
580+
note = "Legacy serialization API is not type-safe and is going to be removed soon"
581+
)]
576582
#[error("Serializing values failed: {0} ")]
583+
#[allow(deprecated)]
577584
SerializeValuesError(#[from] SerializeValuesError),
578585

579586
#[error("Serializing values failed: {0} ")]

0 commit comments

Comments
 (0)