Skip to content

Commit c00ae72

Browse files
committed
serialize/value errors: various fixes for accuracy
- error messages are changed to better reflect reality, - where possible, `write!(f, ...)` is replaced with `f.write_str(...)` for performance.
1 parent 20fbd00 commit c00ae72

File tree

1 file changed

+16
-44
lines changed

1 file changed

+16
-44
lines changed

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

+16-44
Original file line numberDiff line numberDiff line change
@@ -1149,17 +1149,14 @@ impl Display for BuiltinTypeCheckErrorKind {
11491149
write!(f, "expected one of the CQL types: {expected:?}")
11501150
}
11511151
BuiltinTypeCheckErrorKind::NotEmptyable => {
1152-
write!(
1153-
f,
1154-
"the separate empty representation is not valid for this type"
1155-
)
1152+
f.write_str("the separate empty representation is not valid for this type")
11561153
}
11571154
BuiltinTypeCheckErrorKind::SetOrListError(err) => err.fmt(f),
11581155
BuiltinTypeCheckErrorKind::MapError(err) => err.fmt(f),
11591156
BuiltinTypeCheckErrorKind::TupleError(err) => err.fmt(f),
11601157
BuiltinTypeCheckErrorKind::UdtError(err) => err.fmt(f),
11611158
BuiltinTypeCheckErrorKind::CustomTypeUnsupported => {
1162-
write!(f, "custom CQL types are unsupported")
1159+
f.write_str("custom CQL types are unsupported")
11631160
}
11641161
}
11651162
}
@@ -1217,16 +1214,10 @@ impl Display for BuiltinSerializationErrorKind {
12171214
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12181215
match self {
12191216
BuiltinSerializationErrorKind::SizeOverflow => {
1220-
write!(
1221-
f,
1222-
"the Rust value is too big to be serialized in the CQL protocol format"
1223-
)
1217+
f.write_str("the Rust value is too big to be serialized in the CQL protocol format")
12241218
}
12251219
BuiltinSerializationErrorKind::ValueOverflow => {
1226-
write!(
1227-
f,
1228-
"the Rust value is out of range supported by the CQL type"
1229-
)
1220+
f.write_str("the Rust value is out of range supported by the CQL type")
12301221
}
12311222
BuiltinSerializationErrorKind::SetOrListError(err) => err.fmt(f),
12321223
BuiltinSerializationErrorKind::MapError(err) => err.fmt(f),
@@ -1247,12 +1238,9 @@ pub enum MapTypeCheckErrorKind {
12471238
impl Display for MapTypeCheckErrorKind {
12481239
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12491240
match self {
1250-
MapTypeCheckErrorKind::NotMap => {
1251-
write!(
1252-
f,
1253-
"the CQL type the map was attempted to be serialized to was not map"
1254-
)
1255-
}
1241+
MapTypeCheckErrorKind::NotMap => f.write_str(
1242+
"the CQL type the Rust type was attempted to be type checked against was not a map",
1243+
),
12561244
}
12571245
}
12581246
}
@@ -1275,10 +1263,7 @@ impl Display for MapSerializationErrorKind {
12751263
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12761264
match self {
12771265
MapSerializationErrorKind::TooManyElements => {
1278-
write!(
1279-
f,
1280-
"the map contains too many elements to fit in CQL representation"
1281-
)
1266+
f.write_str("the map contains too many elements to fit in CQL representation")
12821267
}
12831268
MapSerializationErrorKind::KeySerializationFailed(err) => {
12841269
write!(f, "failed to serialize one of the keys: {}", err)
@@ -1302,10 +1287,7 @@ impl Display for SetOrListTypeCheckErrorKind {
13021287
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13031288
match self {
13041289
SetOrListTypeCheckErrorKind::NotSetOrList => {
1305-
write!(
1306-
f,
1307-
"the CQL type the tuple was attempted to was neither a set or a list"
1308-
)
1290+
f.write_str("the CQL type the Rust type was attempted to be type checked against was neither a set or a list")
13091291
}
13101292
}
13111293
}
@@ -1325,12 +1307,9 @@ pub enum SetOrListSerializationErrorKind {
13251307
impl Display for SetOrListSerializationErrorKind {
13261308
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13271309
match self {
1328-
SetOrListSerializationErrorKind::TooManyElements => {
1329-
write!(
1330-
f,
1331-
"the collection contains too many elements to fit in CQL representation"
1332-
)
1333-
}
1310+
SetOrListSerializationErrorKind::TooManyElements => f.write_str(
1311+
"the collection contains too many elements to fit in CQL representation",
1312+
),
13341313
SetOrListSerializationErrorKind::ElementSerializationFailed(err) => {
13351314
write!(f, "failed to serialize one of the elements: {err}")
13361315
}
@@ -1362,14 +1341,10 @@ pub enum TupleTypeCheckErrorKind {
13621341
impl Display for TupleTypeCheckErrorKind {
13631342
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13641343
match self {
1365-
TupleTypeCheckErrorKind::NotTuple => write!(
1366-
f,
1367-
"the CQL type the tuple was attempted to be serialized to is not a tuple"
1344+
TupleTypeCheckErrorKind::NotTuple => f.write_str(
1345+
"the CQL type the Rust type was attempted to be type checked against is not a tuple"
13681346
),
1369-
TupleTypeCheckErrorKind::WrongElementCount {
1370-
rust_type_el_count,
1371-
cql_type_el_count,
1372-
} => write!(
1347+
TupleTypeCheckErrorKind::WrongElementCount { rust_type_el_count, cql_type_el_count } => write!(
13731348
f,
13741349
"wrong tuple element count: CQL type has {cql_type_el_count}, the Rust tuple has {rust_type_el_count}"
13751350
),
@@ -1442,10 +1417,7 @@ pub enum UdtTypeCheckErrorKind {
14421417
impl Display for UdtTypeCheckErrorKind {
14431418
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14441419
match self {
1445-
UdtTypeCheckErrorKind::NotUdt => write!(
1446-
f,
1447-
"the CQL type the tuple was attempted to be type checked against is not a UDT"
1448-
),
1420+
UdtTypeCheckErrorKind::NotUdt => f.write_str("the CQL type the Rust type was attempted to be type checked against is not a UDT"),
14491421
UdtTypeCheckErrorKind::NameMismatch {
14501422
keyspace,
14511423
type_name,

0 commit comments

Comments
 (0)