Skip to content
Open
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
112 changes: 52 additions & 60 deletions python/pyarrow/_flight.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class CertKeyPair(_CertKeyPair):
"""A TLS certificate and key for use in Flight."""


cdef class FlightError(Exception):
class FlightError(Exception):
"""
The base class for Flight-specific errors.

Expand All @@ -201,73 +201,65 @@ cdef class FlightError(Exception):
extra_info : bytes
Extra binary error details that were provided by the
server/will be sent to the client.
"""

cdef dict __dict__
"""

def __init__(self, message='', extra_info=b''):
super().__init__(message)
self.extra_info = tobytes(extra_info)

cdef CStatus to_status(self):
message = tobytes(f"Flight error: {self}")
return CStatus_UnknownError(message)


cdef class FlightInternalError(FlightError, ArrowException):
class FlightInternalError(FlightError, ArrowException):
"""An error internal to the Flight server occurred."""

cdef CStatus to_status(self):
return MakeFlightError(CFlightStatusInternal,
tobytes(str(self)), self.extra_info)


cdef class FlightTimedOutError(FlightError, ArrowException):
class FlightTimedOutError(FlightError, ArrowException):
"""The Flight RPC call timed out."""

cdef CStatus to_status(self):
return MakeFlightError(CFlightStatusTimedOut,
tobytes(str(self)), self.extra_info)


cdef class FlightCancelledError(FlightError, ArrowCancelled):
class FlightCancelledError(FlightError, ArrowCancelled):
"""The operation was cancelled."""

cdef CStatus to_status(self):
return MakeFlightError(CFlightStatusCancelled, tobytes(str(self)),
self.extra_info)


cdef class FlightServerError(FlightError, ArrowException):
class FlightServerError(FlightError, ArrowException):
"""A server error occurred."""

cdef CStatus to_status(self):
return MakeFlightError(CFlightStatusFailed, tobytes(str(self)),
self.extra_info)


cdef class FlightUnauthenticatedError(FlightError, ArrowException):
class FlightUnauthenticatedError(FlightError, ArrowException):
"""The client is not authenticated."""

cdef CStatus to_status(self):
return MakeFlightError(
CFlightStatusUnauthenticated, tobytes(str(self)), self.extra_info)


cdef class FlightUnauthorizedError(FlightError, ArrowException):
class FlightUnauthorizedError(FlightError, ArrowException):
"""The client is not authorized to perform the given operation."""

cdef CStatus to_status(self):
return MakeFlightError(CFlightStatusUnauthorized, tobytes(str(self)),
self.extra_info)


cdef class FlightUnavailableError(FlightError, ArrowException):
class FlightUnavailableError(FlightError, ArrowException):
"""The server is not reachable or available."""

cdef CStatus to_status(self):
return MakeFlightError(CFlightStatusUnavailable, tobytes(str(self)),
self.extra_info)

cdef CStatus _flight_error_to_status(error) except *:
extra_info = tobytes(getattr(error, "extra_info", b""))
if isinstance(error, FlightInternalError):
return MakeFlightError(CFlightStatusInternal, tobytes(str(error)),
extra_info)
elif isinstance(error, FlightTimedOutError):
return MakeFlightError(CFlightStatusTimedOut, tobytes(str(error)),
extra_info)
elif isinstance(error, FlightCancelledError):
return MakeFlightError(CFlightStatusCancelled, tobytes(str(error)),
extra_info)
elif isinstance(error, FlightServerError):
return MakeFlightError(CFlightStatusFailed, tobytes(str(error)),
extra_info)
elif isinstance(error, FlightUnauthenticatedError):
return MakeFlightError(CFlightStatusUnauthenticated, tobytes(str(error)),
extra_info)
elif isinstance(error, FlightUnauthorizedError):
return MakeFlightError(CFlightStatusUnauthorized, tobytes(str(error)),
extra_info)
elif isinstance(error, FlightUnavailableError):
return MakeFlightError(CFlightStatusUnavailable, tobytes(str(error)),
extra_info)
return CStatus_UnknownError(tobytes(f"Flight error: {error}"))


class FlightWriteSizeExceededError(ArrowInvalid):
Expand Down Expand Up @@ -2140,7 +2132,7 @@ cdef CStatus _data_stream_next(void* self, CFlightPayload* payload) except *:
payload.ipc_message.metadata.reset(<CBuffer*> nullptr)
return CStatus_OK()
except FlightError as flight_error:
return (<FlightError> flight_error).to_status()
return _flight_error_to_status(flight_error)

if isinstance(result, (list, tuple)):
result, metadata = result
Expand Down Expand Up @@ -2214,7 +2206,7 @@ cdef CStatus _list_flights(void* self, const CServerCallContext& context,
flights.push_back(deref((<FlightInfo> info).info.get()))
listing.reset(new CSimpleFlightListing(flights))
except FlightError as flight_error:
return (<FlightError> flight_error).to_status()
return _flight_error_to_status(flight_error)
return CStatus_OK()


Expand All @@ -2231,7 +2223,7 @@ cdef CStatus _get_flight_info(void* self, const CServerCallContext& context,
ServerCallContext.wrap(context),
py_descriptor)
except FlightError as flight_error:
return (<FlightError> flight_error).to_status()
return _flight_error_to_status(flight_error)
if not isinstance(result, FlightInfo):
raise TypeError("FlightServerBase.get_flight_info must return "
f"a FlightInfo instance, but got {type(result)}")
Expand Down Expand Up @@ -2272,7 +2264,7 @@ cdef CStatus _do_put(void* self, const CServerCallContext& context,
py_reader, py_writer)
return CStatus_OK()
except FlightError as flight_error:
return (<FlightError> flight_error).to_status()
return _flight_error_to_status(flight_error)


cdef CStatus _do_get(void* self, const CServerCallContext& context,
Expand All @@ -2287,7 +2279,7 @@ cdef CStatus _do_get(void* self, const CServerCallContext& context,
result = (<object> self).do_get(ServerCallContext.wrap(context),
py_ticket)
except FlightError as flight_error:
return (<FlightError> flight_error).to_status()
return _flight_error_to_status(flight_error)
if not isinstance(result, FlightDataStream):
raise TypeError("FlightServerBase.do_get must return "
"a FlightDataStream")
Expand Down Expand Up @@ -2316,7 +2308,7 @@ cdef CStatus _do_exchange(void* self, const CServerCallContext& context,
descriptor, py_reader, py_writer)
return CStatus_OK()
except FlightError as flight_error:
return (<FlightError> flight_error).to_status()
return _flight_error_to_status(flight_error)


cdef CStatus _do_action_result_next(
Expand All @@ -2336,7 +2328,7 @@ cdef CStatus _do_action_result_next(
except StopIteration:
result.reset(nullptr)
except FlightError as flight_error:
return (<FlightError> flight_error).to_status()
return _flight_error_to_status(flight_error)
return CStatus_OK()


Expand All @@ -2351,7 +2343,7 @@ cdef CStatus _do_action(void* self, const CServerCallContext& context,
responses = (<object> self).do_action(ServerCallContext.wrap(context),
py_action)
except FlightError as flight_error:
return (<FlightError> flight_error).to_status()
return _flight_error_to_status(flight_error)
# Let the application return an iterator or anything convertible
# into one
if responses is None:
Expand All @@ -2377,7 +2369,7 @@ cdef CStatus _list_actions(void* self, const CServerCallContext& context,
action_type.description = tobytes(action[1])
actions.push_back(action_type)
except FlightError as flight_error:
return (<FlightError> flight_error).to_status()
return _flight_error_to_status(flight_error)
return CStatus_OK()


Expand All @@ -2389,7 +2381,7 @@ cdef CStatus _server_authenticate(void* self, CServerAuthSender* outgoing,
try:
(<object> self).authenticate(sender, reader)
except FlightError as flight_error:
return (<FlightError> flight_error).to_status()
return _flight_error_to_status(flight_error)
finally:
sender.poison()
reader.poison()
Expand All @@ -2403,7 +2395,7 @@ cdef CStatus _is_valid(void* self, const c_string& token,
c_result = tobytes((<object> self).is_valid(token))
peer_identity[0] = c_result
except FlightError as flight_error:
return (<FlightError> flight_error).to_status()
return _flight_error_to_status(flight_error)
return CStatus_OK()


Expand All @@ -2415,7 +2407,7 @@ cdef CStatus _client_authenticate(void* self, CClientAuthSender* outgoing,
try:
(<object> self).authenticate(sender, reader)
except FlightError as flight_error:
return (<FlightError> flight_error).to_status()
return _flight_error_to_status(flight_error)
finally:
sender.poison()
reader.poison()
Expand All @@ -2429,7 +2421,7 @@ cdef CStatus _get_token(void* self, c_string* token) except *:
c_result = tobytes((<object> self).get_token())
token[0] = c_result
except FlightError as flight_error:
return (<FlightError> flight_error).to_status()
return _flight_error_to_status(flight_error)
return CStatus_OK()


Expand All @@ -2439,7 +2431,7 @@ cdef CStatus _middleware_sending_headers(
try:
headers = (<object> self).sending_headers()
except FlightError as flight_error:
return (<FlightError> flight_error).to_status()
return _flight_error_to_status(flight_error)

if headers:
for header, values in headers.items():
Expand Down Expand Up @@ -2471,7 +2463,7 @@ cdef CStatus _middleware_call_completed(
else:
(<object> self).call_completed(None)
except FlightError as flight_error:
return (<FlightError> flight_error).to_status()
return _flight_error_to_status(flight_error)
return CStatus_OK()


Expand All @@ -2483,7 +2475,7 @@ cdef CStatus _middleware_received_headers(
headers = convert_headers(c_headers)
(<object> self).received_headers(headers)
except FlightError as flight_error:
return (<FlightError> flight_error).to_status()
return _flight_error_to_status(flight_error)
return CStatus_OK()


Expand Down Expand Up @@ -2516,7 +2508,7 @@ cdef CStatus _server_middleware_start_call(
headers = convert_headers(c_headers)
instance = (<object> self).start_call(call_info, headers)
except FlightError as flight_error:
return (<FlightError> flight_error).to_status()
return _flight_error_to_status(flight_error)

if instance:
ServerMiddleware.wrap(instance, c_instance)
Expand All @@ -2534,7 +2526,7 @@ cdef CStatus _client_middleware_start_call(
call_info = wrap_call_info(c_info)
instance = (<object> self).start_call(call_info)
except FlightError as flight_error:
return (<FlightError> flight_error).to_status()
return _flight_error_to_status(flight_error)

if instance:
ClientMiddleware.wrap(instance, c_instance)
Expand Down
Loading