Skip to content

Commit 2ec2885

Browse files
piodulwprzytula
andcommitted
connection: switch to the new deserialization framework
Adjusts `Connection::fetch_schema_version` to use the new deserialization API. Connection is meant to be an internal API, so we don't introduce a LegacyConnection for this. `Connection::{query,execute}_iter` will be migrated in a further commit. Co-authored-by: Wojciech Przytuła <[email protected]>
1 parent 22f28cd commit 2ec2885

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

scylla/src/transport/connection.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use std::{
4646
net::{Ipv4Addr, Ipv6Addr},
4747
};
4848

49-
use super::errors::{ProtocolError, UseKeyspaceProtocolError};
49+
use super::errors::{ProtocolError, SchemaVersionFetchError, UseKeyspaceProtocolError};
5050
use super::iterator::{LegacyRowIterator, QueryPager};
5151
use super::locator::tablets::{RawTablet, TabletParsingError};
5252
use super::query_result::QueryResult;
@@ -1436,9 +1436,15 @@ impl Connection {
14361436
let (version_id,) = self
14371437
.query_unpaged(LOCAL_VERSION)
14381438
.await?
1439-
.into_legacy_result()?
1440-
.single_row_typed()
1441-
.map_err(ProtocolError::SchemaVersionFetch)?;
1439+
.into_rows_result()?
1440+
.ok_or(QueryError::ProtocolError(
1441+
ProtocolError::SchemaVersionFetch(SchemaVersionFetchError::ResultNotRows),
1442+
))?
1443+
.single_row::<(Uuid,)>()
1444+
.map_err(|err| {
1445+
ProtocolError::SchemaVersionFetch(SchemaVersionFetchError::SingleRowError(err))
1446+
})?;
1447+
14421448
Ok(version_id)
14431449
}
14441450

scylla/src/transport/errors.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use thiserror::Error;
3232

3333
use crate::{authentication::AuthError, frame::response};
3434

35-
use super::legacy_query_result::{RowsExpectedError, SingleRowTypedError};
35+
use super::{legacy_query_result::RowsExpectedError, query_result::SingleRowError};
3636

3737
/// Error that occurred during query execution
3838
#[derive(Error, Debug, Clone)]
@@ -304,7 +304,7 @@ pub enum ProtocolError {
304304

305305
/// A protocol error appeared during schema version fetch.
306306
#[error("Schema version fetch protocol error: {0}")]
307-
SchemaVersionFetch(SingleRowTypedError),
307+
SchemaVersionFetch(#[from] SchemaVersionFetchError),
308308

309309
/// A result with nonfinished paging state received for unpaged query.
310310
#[error("Unpaged query returned a non-empty paging state! This is a driver-side or server-side bug.")]
@@ -345,6 +345,16 @@ pub enum UseKeyspaceProtocolError {
345345
UnexpectedResponse(CqlResponseKind),
346346
}
347347

348+
/// A protocol error that occurred during schema version fetch.
349+
#[derive(Error, Debug, Clone)]
350+
#[non_exhaustive]
351+
pub enum SchemaVersionFetchError {
352+
#[error("Schema version query returned non-rows result")]
353+
ResultNotRows,
354+
#[error(transparent)]
355+
SingleRowError(SingleRowError),
356+
}
357+
348358
/// A protocol error that occurred during tracing info fetch.
349359
#[derive(Error, Debug, Clone)]
350360
#[non_exhaustive]

0 commit comments

Comments
 (0)