Skip to content

Commit 04c7eec

Browse files
committed
iterator: return NextRowError from next() methods
1 parent a140f7f commit 04c7eec

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

scylla/src/client/pager.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::cluster::{ClusterState, NodeRef};
2929
#[allow(deprecated)]
3030
use crate::cql_to_rust::{FromRow, FromRowError};
3131
use crate::deserialize::DeserializeOwnedRow;
32-
use crate::errors::{QueryError, RequestAttemptError, RequestError};
32+
use crate::errors::{RequestAttemptError, RequestError};
3333
use crate::frame::response::result;
3434
use crate::network::Connection;
3535
use crate::observability::driver_tracing::RequestSpan;
@@ -584,11 +584,11 @@ impl QueryPager {
584584
/// borrows from self.
585585
///
586586
/// This is cancel-safe.
587-
async fn next(&mut self) -> Option<Result<ColumnIterator, QueryError>> {
587+
async fn next(&mut self) -> Option<Result<ColumnIterator, NextRowError>> {
588588
let res = std::future::poll_fn(|cx| Pin::new(&mut *self).poll_fill_page(cx)).await;
589589
match res {
590590
Some(Ok(())) => {}
591-
Some(Err(err)) => return Some(Err(err.into())),
591+
Some(Err(err)) => return Some(Err(err)),
592592
None => return None,
593593
}
594594

@@ -597,7 +597,7 @@ impl QueryPager {
597597
self.current_page
598598
.next()
599599
.unwrap()
600-
.map_err(|err| NextRowError::RowDeserializationError(err).into()),
600+
.map_err(NextRowError::RowDeserializationError),
601601
)
602602
}
603603

@@ -1035,14 +1035,14 @@ impl<RowT> Stream for TypedRowStream<RowT>
10351035
where
10361036
RowT: DeserializeOwnedRow,
10371037
{
1038-
type Item = Result<RowT, QueryError>;
1038+
type Item = Result<RowT, NextRowError>;
10391039

10401040
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
10411041
let next_fut = async {
10421042
self.raw_row_lending_stream.next().await.map(|res| {
10431043
res.and_then(|column_iterator| {
10441044
<RowT as DeserializeRow>::deserialize(column_iterator)
1045-
.map_err(|err| NextRowError::RowDeserializationError(err).into())
1045+
.map_err(NextRowError::RowDeserializationError)
10461046
})
10471047
})
10481048
};
@@ -1177,7 +1177,7 @@ mod legacy {
11771177
pub enum LegacyNextRowError {
11781178
/// Query to fetch next page has failed
11791179
#[error(transparent)]
1180-
QueryError(#[from] QueryError),
1180+
NextRowError(#[from] NextRowError),
11811181

11821182
/// Parsing values in row as given types failed
11831183
#[error(transparent)]

scylla/src/cluster/metadata.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ async fn query_peers(conn: &Arc<Connection>, connect_port: u16) -> Result<Vec<Pe
847847
Ok::<_, QueryError>(rows_stream)
848848
})
849849
.into_stream()
850+
.map(|result| result.map(|stream| stream.map_err(QueryError::from)))
850851
.try_flatten()
851852
.and_then(|row_result| future::ok((NodeInfoSource::Peer, row_result)));
852853

@@ -864,6 +865,7 @@ async fn query_peers(conn: &Arc<Connection>, connect_port: u16) -> Result<Vec<Pe
864865
Ok::<_, QueryError>(rows_stream)
865866
})
866867
.into_stream()
868+
.map(|result| result.map(|stream| stream.map_err(QueryError::from)))
867869
.try_flatten()
868870
.and_then(|row_result| future::ok((NodeInfoSource::Local, row_result)));
869871

@@ -1007,7 +1009,9 @@ where
10071009
pager.rows_stream::<R>().map_err(convert_typecheck_error)?;
10081010
Ok::<_, QueryError>(stream)
10091011
};
1010-
fut.into_stream().try_flatten()
1012+
fut.into_stream()
1013+
.map(|result| result.map(|stream| stream.map_err(QueryError::from)))
1014+
.try_flatten()
10111015
}
10121016

10131017
async fn query_keyspaces(
@@ -1861,6 +1865,7 @@ async fn query_table_partitioners(
18611865
Ok::<_, QueryError>(stream)
18621866
})
18631867
.into_stream()
1868+
.map(|result| result.map(|stream| stream.map_err(QueryError::from)))
18641869
.try_flatten();
18651870

18661871
let result = rows

0 commit comments

Comments
 (0)