Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove uses of SerializeValuesError and deprecate it #1149

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions scylla-cql/src/frame/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -684,6 +663,22 @@ mod legacy {
fn serialize(&self, buf: &mut Vec<u8>) -> 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)]
Expand Down Expand Up @@ -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,
};
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
7 changes: 7 additions & 0 deletions scylla/src/transport/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::{
sync::Arc,
};

#[allow(deprecated)]
use scylla_cql::{
frame::{
frame_errors::{
Expand Down Expand Up @@ -124,6 +125,7 @@ pub enum QueryError {
IntoLegacyQueryResultError(#[from] IntoLegacyQueryResultError),
}

#[allow(deprecated)]
impl From<SerializeValuesError> for QueryError {
fn from(serialized_err: SerializeValuesError) -> QueryError {
QueryError::BadQuery(BadQuery::SerializeValuesError(serialized_err))
Expand Down Expand Up @@ -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} ")]
Expand Down
Loading