Improve error message by including the error code

pull/22343/head
Mariano Anaya 5 years ago committed by Lidi Zheng
parent 4ec09a0a26
commit 764be7ed92
  1. 14
      src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi
  2. 9
      src/python/grpcio_tests/tests_aio/unit/_test_server.py

@ -125,7 +125,7 @@ cdef class _AioCall(GrpcCallWrapper):
if credentials is not None: if credentials is not None:
set_credentials_error = grpc_call_set_credentials(self.call, credentials.c()) set_credentials_error = grpc_call_set_credentials(self.call, credentials.c())
if set_credentials_error != GRPC_CALL_OK: if set_credentials_error != GRPC_CALL_OK:
raise RuntimeError("Credentials couldn't have been set") raise RuntimeError(f"Credentials couldn't have been set: {set_credentials_error}")
grpc_slice_unref(method_slice) grpc_slice_unref(method_slice)
@ -209,7 +209,7 @@ cdef class _AioCall(GrpcCallWrapper):
def done(self): def done(self):
"""Returns if the RPC call has finished. """Returns if the RPC call has finished.
Checks if the status has been provided, either Checks if the status has been provided, either
because the RPC finished or because was cancelled.. because the RPC finished or because was cancelled..
@ -220,7 +220,7 @@ cdef class _AioCall(GrpcCallWrapper):
def cancelled(self): def cancelled(self):
"""Returns if the RPC was cancelled. """Returns if the RPC was cancelled.
Returns: Returns:
True if the RPC was cancelled. True if the RPC was cancelled.
""" """
@ -231,7 +231,7 @@ cdef class _AioCall(GrpcCallWrapper):
async def status(self): async def status(self):
"""Returns the status of the RPC call. """Returns the status of the RPC call.
It returns the finshed status of the RPC. If the RPC It returns the finshed status of the RPC. If the RPC
has not finished yet this function will wait until the RPC has not finished yet this function will wait until the RPC
gets finished. gets finished.
@ -254,7 +254,7 @@ cdef class _AioCall(GrpcCallWrapper):
async def initial_metadata(self): async def initial_metadata(self):
"""Returns the initial metadata of the RPC call. """Returns the initial metadata of the RPC call.
If the initial metadata has not been received yet this function will If the initial metadata has not been received yet this function will
wait until the RPC gets finished. wait until the RPC gets finished.
@ -420,7 +420,7 @@ cdef class _AioCall(GrpcCallWrapper):
tuple outbound_initial_metadata, tuple outbound_initial_metadata,
object metadata_sent_observer): object metadata_sent_observer):
"""Actual implementation of the complete unary-stream call. """Actual implementation of the complete unary-stream call.
Needs to pay extra attention to the raise mechanism. If we want to Needs to pay extra attention to the raise mechanism. If we want to
propagate the final status exception, then we have to raise it. propagate the final status exception, then we have to raise it.
Othersize, it would end normally and raise `StopAsyncIteration()`. Othersize, it would end normally and raise `StopAsyncIteration()`.
@ -490,7 +490,7 @@ cdef class _AioCall(GrpcCallWrapper):
outbound_initial_metadata, outbound_initial_metadata,
self._send_initial_metadata_flags, self._send_initial_metadata_flags,
self._loop) self._loop)
# Notify upper level that sending messages are allowed now. # Notify upper level that sending messages are allowed now.
metadata_sent_observer() metadata_sent_observer()
# Receives initial metadata. # Receives initial metadata.

@ -24,6 +24,10 @@ from tests_aio.unit import _constants
_INITIAL_METADATA_KEY = "x-grpc-test-echo-initial" _INITIAL_METADATA_KEY = "x-grpc-test-echo-initial"
_TRAILING_METADATA_KEY = "x-grpc-test-echo-trailing-bin" _TRAILING_METADATA_KEY = "x-grpc-test-echo-trailing-bin"
_PRIVATE_KEY = resources.private_key()
_CERTIFICATE_CHAIN = resources.certificate_chain()
_TEST_ROOT_CERTIFICATES = resources.test_root_certificates()
_SERVER_CERTS = ((_PRIVATE_KEY, _CERTIFICATE_CHAIN),)
async def _maybe_echo_metadata(servicer_context): async def _maybe_echo_metadata(servicer_context):
@ -38,11 +42,6 @@ async def _maybe_echo_metadata(servicer_context):
invocation_metadata[_TRAILING_METADATA_KEY]) invocation_metadata[_TRAILING_METADATA_KEY])
servicer_context.set_trailing_metadata((trailing_metadatum,)) servicer_context.set_trailing_metadata((trailing_metadatum,))
_PRIVATE_KEY = resources.private_key()
_CERTIFICATE_CHAIN = resources.certificate_chain()
_TEST_ROOT_CERTIFICATES = resources.test_root_certificates()
_SERVER_CERTS = ((_PRIVATE_KEY, _CERTIFICATE_CHAIN),)
async def _maybe_echo_status(request: messages_pb2.SimpleRequest, async def _maybe_echo_status(request: messages_pb2.SimpleRequest,
servicer_context): servicer_context):

Loading…
Cancel
Save