Skip to content

Commit

Permalink
serialize/row: get rid of legacy SerializeValuesError
Browse files Browse the repository at this point in the history
Only one variant of the legacy SerializeValuesError was used:
TooManyValues. In order to remove it entirely, a corresponding variant
is introduced to the BuiltinSerializationErrorKind.
  • Loading branch information
wprzytula committed Dec 11, 2024
1 parent 868d86f commit 04c6f31
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
2 changes: 2 additions & 0 deletions scylla-cql/src/types/serialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Error + Send + Sync>);
Expand Down
37 changes: 27 additions & 10 deletions scylla-cql/src/types/serialize/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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"
)
}
}
}
}
Expand Down Expand Up @@ -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::<Self>(
BuiltinSerializationErrorKind::TooManyValues,
))));
}
};

Expand Down Expand Up @@ -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::<Self>(
BuiltinSerializationErrorKind::TooManyValues,
))));
}

let len_before_serialize: usize = self.serialized_values.len();
Expand Down Expand Up @@ -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");
}

Expand All @@ -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::<Vec<&str>>());
let BuiltinSerializationErrorKind::ColumnSerializationFailed { name, err: _ } = &err.kind;
let BuiltinSerializationErrorKind::ColumnSerializationFailed { name, err: _ } = &err.kind
else {
panic!("Expected BuiltinSerializationErrorKind::ColumnSerializationFailed")
};
assert_eq!(name, "b");
}

Expand Down Expand Up @@ -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::<BTreeMap<&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");
}

Expand Down

0 comments on commit 04c6f31

Please sign in to comment.