Skip to content

Commit e45d2f9

Browse files
committed
Reapply "Box FlightErrror::tonic to reduce size (fixes nightly clippy) (apache#7229)" (apache#7266)
This reverts commit f4fde76.
1 parent 9c9d5d1 commit e45d2f9

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

arrow-flight/src/client.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl FlightClient {
210210
let (response_stream, trailers) = extract_lazy_trailers(response_stream);
211211

212212
Ok(FlightRecordBatchStream::new_from_flight_data(
213-
response_stream.map_err(FlightError::Tonic),
213+
response_stream.map_err(|status| status.into()),
214214
)
215215
.with_headers(md)
216216
.with_trailers(trailers))
@@ -470,7 +470,7 @@ impl FlightClient {
470470
.list_flights(request)
471471
.await?
472472
.into_inner()
473-
.map_err(FlightError::Tonic);
473+
.map_err(|status| status.into());
474474

475475
Ok(response.boxed())
476476
}
@@ -537,7 +537,7 @@ impl FlightClient {
537537
.list_actions(request)
538538
.await?
539539
.into_inner()
540-
.map_err(FlightError::Tonic);
540+
.map_err(|status| status.into());
541541

542542
Ok(action_stream.boxed())
543543
}
@@ -575,7 +575,7 @@ impl FlightClient {
575575
.do_action(request)
576576
.await?
577577
.into_inner()
578-
.map_err(FlightError::Tonic)
578+
.map_err(|status| status.into())
579579
.map(|r| {
580580
r.map(|r| {
581581
// unwrap inner bytes

arrow-flight/src/error.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub enum FlightError {
2727
/// Returned when functionality is not yet available.
2828
NotYetImplemented(String),
2929
/// Error from the underlying tonic library
30-
Tonic(tonic::Status),
30+
Tonic(Box<tonic::Status>),
3131
/// Some unexpected message was received
3232
ProtocolError(String),
3333
/// An error occurred during decoding
@@ -74,7 +74,7 @@ impl Error for FlightError {
7474

7575
impl From<tonic::Status> for FlightError {
7676
fn from(status: tonic::Status) -> Self {
77-
Self::Tonic(status)
77+
Self::Tonic(Box::new(status))
7878
}
7979
}
8080

@@ -91,7 +91,7 @@ impl From<FlightError> for tonic::Status {
9191
match value {
9292
FlightError::Arrow(e) => tonic::Status::internal(e.to_string()),
9393
FlightError::NotYetImplemented(e) => tonic::Status::internal(e),
94-
FlightError::Tonic(status) => status,
94+
FlightError::Tonic(status) => *status,
9595
FlightError::ProtocolError(e) => tonic::Status::internal(e),
9696
FlightError::DecodeError(e) => tonic::Status::internal(e),
9797
FlightError::ExternalError(e) => tonic::Status::internal(e.to_string()),
@@ -147,4 +147,10 @@ mod test {
147147
let source = root_error.downcast_ref::<FlightError>().unwrap();
148148
assert!(matches!(source, FlightError::DecodeError(_)));
149149
}
150+
151+
#[test]
152+
fn test_error_size() {
153+
// use Box in variants to keep this size down
154+
assert_eq!(std::mem::size_of::<FlightError>(), 32);
155+
}
150156
}

arrow-flight/src/sql/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ impl FlightSqlServiceClient<Channel> {
309309
let (response_stream, trailers) = extract_lazy_trailers(response_stream);
310310

311311
Ok(FlightRecordBatchStream::new_from_flight_data(
312-
response_stream.map_err(FlightError::Tonic),
312+
response_stream.map_err(|status| status.into()),
313313
)
314314
.with_headers(md)
315315
.with_trailers(trailers))

arrow-flight/src/streams.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl<T> Stream for FallibleTonicResponseStream<T> {
127127

128128
match ready!(pinned.response_stream.poll_next_unpin(cx)) {
129129
Some(Ok(res)) => Poll::Ready(Some(Ok(res))),
130-
Some(Err(status)) => Poll::Ready(Some(Err(FlightError::Tonic(status)))),
130+
Some(Err(status)) => Poll::Ready(Some(Err(status.into()))),
131131
None => Poll::Ready(None),
132132
}
133133
}

0 commit comments

Comments
 (0)