So, this is the unit test code that fails (the stub and server are
initialized in the setUp):
def test_list_invalid(self):
request = service_pb2.Request()
with self.assertRaises(expected_exception=grpc.RpcError) as error:
for _ in self.stub.StreamEndpoint(request):
pass
self.assertEqual(error.exception.code(), grpc.StatusCode.
INVALID_ARGUMENT)
This test completes with AssertionError: RpcError not raised. Although, if
I check the response, it does have the correct status code.
On Tuesday, August 21, 2018 at 4:31:40 PM UTC+1, Mehrdad Afshari wrote:
>
> Can you please share a minimal client code that exhibits the behavior?
>
> On Tue, Aug 21, 2018 at 6:22 AM <[email protected] <javascript:>> wrote:
>
>> Hi,
>>
>> I've been trying ascertain the correct way to handle error behaviour from
>> streaming endpoints.
>>
>> My code effectively does the following:
>>
>> service MyService {
>> rpc StreamEndpoint(Request) returns (stream Response)
>> }
>>
>> message Request {
>> repeated string query_ids = 1;
>> }
>>
>> message Response {
>> string object_id = 1;
>> }
>>
>> class MyService(MyServiceServicer):
>>
>> def StreamEndpoint(self, request, context):
>> if not request.query_ids:
>> context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
>> context.set_details('Must set at least one id')
>> yield Empty()
>> for obj in self.db.query(id_list=request.query_ids):
>> yield obj.to_protobuf()
>>
>>
>> I was expecting the client upon calling StreamEndpoint without query_ids
>> to throw an RpcError (the client is also in Python) upon getting a code
>> that isn't OK. However, it doesn't, even though the code in the response is
>> correctly set to INVALID_ARGUMENT.
>>
>> Is this the correct behaviour? If so, what is usually the recommended way
>> of handling these errors in python, as I have relied on the exception on
>> non-streaming endpoints.
>>
>> Thanks
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "grpc.io" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/grpc-io.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/grpc-io/92a1d587-c1d6-4e71-92ab-4d428d8c2152%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/grpc-io/92a1d587-c1d6-4e71-92ab-4d428d8c2152%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
--
You received this message because you are subscribed to the Google Groups
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit
https://groups.google.com/d/msgid/grpc-io/ebce204f-16b6-4a05-90db-f410ea24f07e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.