Skip to content

Commit 20fbd00

Browse files
committed
serialize: polish row WrongColumnCount error
- names and error messages are changed to better reflect reality.
1 parent 406128c commit 20fbd00

File tree

1 file changed

+18
-18
lines changed
  • scylla-cql/src/types/serialize

1 file changed

+18
-18
lines changed

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

+18-18
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ macro_rules! impl_serialize_row_for_unit {
108108
if !ctx.columns().is_empty() {
109109
return Err(mk_typck_err::<Self>(
110110
BuiltinTypeCheckErrorKind::WrongColumnCount {
111-
actual: 0,
112-
asked_for: ctx.columns().len(),
111+
rust_cols: 0,
112+
cql_cols: ctx.columns().len(),
113113
},
114114
));
115115
}
@@ -142,8 +142,8 @@ macro_rules! impl_serialize_row_for_slice {
142142
if ctx.columns().len() != self.len() {
143143
return Err(mk_typck_err::<Self>(
144144
BuiltinTypeCheckErrorKind::WrongColumnCount {
145-
actual: self.len(),
146-
asked_for: ctx.columns().len(),
145+
rust_cols: self.len(),
146+
cql_cols: ctx.columns().len(),
147147
},
148148
));
149149
}
@@ -289,8 +289,8 @@ macro_rules! impl_tuple {
289289
[$($tidents),*] => ($($tidents,)*),
290290
_ => return Err(mk_typck_err::<Self>(
291291
BuiltinTypeCheckErrorKind::WrongColumnCount {
292-
actual: $length,
293-
asked_for: ctx.columns().len(),
292+
rust_cols: $length,
293+
cql_cols: ctx.columns().len(),
294294
},
295295
)),
296296
};
@@ -582,13 +582,13 @@ fn mk_ser_err_named(
582582
#[derive(Debug, Clone)]
583583
#[non_exhaustive]
584584
pub enum BuiltinTypeCheckErrorKind {
585-
/// The Rust type expects `actual` column, but the statement requires `asked_for`.
585+
/// The Rust type provides `rust_cols` columns, but the statement operates on `cql_cols`.
586586
WrongColumnCount {
587587
/// The number of values that the Rust type provides.
588-
actual: usize,
588+
rust_cols: usize,
589589

590-
/// The number of columns that the statement requires.
591-
asked_for: usize,
590+
/// The number of columns that the statement operates on.
591+
cql_cols: usize,
592592
},
593593

594594
/// The Rust type provides a value for some column, but that column is not
@@ -618,8 +618,8 @@ pub enum BuiltinTypeCheckErrorKind {
618618
impl Display for BuiltinTypeCheckErrorKind {
619619
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
620620
match self {
621-
BuiltinTypeCheckErrorKind::WrongColumnCount { actual, asked_for } => {
622-
write!(f, "wrong column count: the query requires {asked_for} columns, but {actual} were provided")
621+
BuiltinTypeCheckErrorKind::WrongColumnCount { rust_cols, cql_cols } => {
622+
write!(f, "wrong column count: the statement operates on {cql_cols} columns, but the given rust type provides {rust_cols}")
623623
}
624624
BuiltinTypeCheckErrorKind::NoColumnWithName { name } => {
625625
write!(
@@ -1048,8 +1048,8 @@ mod tests {
10481048
assert_matches!(
10491049
err.kind,
10501050
BuiltinTypeCheckErrorKind::WrongColumnCount {
1051-
actual: 0,
1052-
asked_for: 1,
1051+
rust_cols: 0,
1052+
cql_cols: 1,
10531053
}
10541054
);
10551055

@@ -1063,8 +1063,8 @@ mod tests {
10631063
assert_matches!(
10641064
err.kind,
10651065
BuiltinTypeCheckErrorKind::WrongColumnCount {
1066-
actual: 1,
1067-
asked_for: 2,
1066+
rust_cols: 1,
1067+
cql_cols: 2,
10681068
}
10691069
);
10701070

@@ -1090,8 +1090,8 @@ mod tests {
10901090
assert_matches!(
10911091
err.kind,
10921092
BuiltinTypeCheckErrorKind::WrongColumnCount {
1093-
actual: 1,
1094-
asked_for: 2,
1093+
rust_cols: 1,
1094+
cql_cols: 2,
10951095
}
10961096
);
10971097

0 commit comments

Comments
 (0)