Skip to content

Box FlightErrror::tonic to reduce size (fixes nightly clippy) #7229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions arrow-flight/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl FlightClient {
let (response_stream, trailers) = extract_lazy_trailers(response_stream);

Ok(FlightRecordBatchStream::new_from_flight_data(
response_stream.map_err(FlightError::Tonic),
response_stream.map_err(|status| status.into()),
)
.with_headers(md)
.with_trailers(trailers))
Expand Down Expand Up @@ -470,7 +470,7 @@ impl FlightClient {
.list_flights(request)
.await?
.into_inner()
.map_err(FlightError::Tonic);
.map_err(|status| status.into());

Ok(response.boxed())
}
Expand Down Expand Up @@ -537,7 +537,7 @@ impl FlightClient {
.list_actions(request)
.await?
.into_inner()
.map_err(FlightError::Tonic);
.map_err(|status| status.into());

Ok(action_stream.boxed())
}
Expand Down Expand Up @@ -575,7 +575,7 @@ impl FlightClient {
.do_action(request)
.await?
.into_inner()
.map_err(FlightError::Tonic)
.map_err(|status| status.into())
.map(|r| {
r.map(|r| {
// unwrap inner bytes
Expand Down
12 changes: 9 additions & 3 deletions arrow-flight/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub enum FlightError {
/// Returned when functionality is not yet available.
NotYetImplemented(String),
/// Error from the underlying tonic library
Tonic(tonic::Status),
Tonic(Box<tonic::Status>),
/// Some unexpected message was received
ProtocolError(String),
/// An error occurred during decoding
Expand Down Expand Up @@ -74,7 +74,7 @@ impl Error for FlightError {

impl From<tonic::Status> for FlightError {
fn from(status: tonic::Status) -> Self {
Self::Tonic(status)
Self::Tonic(Box::new(status))
}
}

Expand All @@ -91,7 +91,7 @@ impl From<FlightError> for tonic::Status {
match value {
FlightError::Arrow(e) => tonic::Status::internal(e.to_string()),
FlightError::NotYetImplemented(e) => tonic::Status::internal(e),
FlightError::Tonic(status) => status,
FlightError::Tonic(status) => *status,
FlightError::ProtocolError(e) => tonic::Status::internal(e),
FlightError::DecodeError(e) => tonic::Status::internal(e),
FlightError::ExternalError(e) => tonic::Status::internal(e.to_string()),
Expand Down Expand Up @@ -147,4 +147,10 @@ mod test {
let source = root_error.downcast_ref::<FlightError>().unwrap();
assert!(matches!(source, FlightError::DecodeError(_)));
}

#[test]
fn test_error_size() {
// use Box in variants to keep this size down
assert_eq!(std::mem::size_of::<FlightError>(), 32);
}
}
2 changes: 1 addition & 1 deletion arrow-flight/src/sql/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl FlightSqlServiceClient<Channel> {
let (response_stream, trailers) = extract_lazy_trailers(response_stream);

Ok(FlightRecordBatchStream::new_from_flight_data(
response_stream.map_err(FlightError::Tonic),
response_stream.map_err(|status| status.into()),
)
.with_headers(md)
.with_trailers(trailers))
Expand Down
2 changes: 1 addition & 1 deletion arrow-flight/src/streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<T> Stream for FallibleTonicResponseStream<T> {

match ready!(pinned.response_stream.poll_next_unpin(cx)) {
Some(Ok(res)) => Poll::Ready(Some(Ok(res))),
Some(Err(status)) => Poll::Ready(Some(Err(FlightError::Tonic(status)))),
Some(Err(status)) => Poll::Ready(Some(Err(status.into()))),
None => Poll::Ready(None),
}
}
Expand Down
Loading