https://pact.io logo
Title
s

Scott Coplin

05/25/2023, 11:38 PM
Greetings! My team is trying to start using Pact in an ecosystem of scala-based gRPC microservices. One of the things I’m encouraging is the use of well-defined gRPC status codes when applicable. It seems to me that these codes can be meaningful in a contract. For example, we could use
NOT_FOUND
as a means to communicate non-existence of an entity. If the provider changed behavior to return
INVALID_ARGUMENT
instead in the same situation it would clearly break clients. Is there a way to write a consumer test matching on gRPC response status? An example would be ideal. I’m fearing there may not be based upon this code which seems to only perform validations on non-error responses, but I am not 100% sure I’m looking in the right spot.
u

uglyog

05/25/2023, 11:43 PM
This is a good idea. Can you raise an issue for this on the GitHub project?
BTW, I found the support for gRPC status codes not very good. The Rust tonic library deals with it properly, but the gRPC Java library seems to ignore it and tries to read the messages anyway.
s

Scott Coplin

05/26/2023, 12:18 AM
@uglyog Sure, I can do that. Here I assume? https://github.com/pactflow/pact-protobuf-plugin Curious what you’ve seen from gRPC Java with respect to this? We tend to see actual non-OK status codes come back as
StatusRuntimeException
. Haven’t seen the ignoring issue, but maybe we’re using a different library (scalapb wrapper on grpc-netty) or you’re coming in at a different layer?
u

uglyog

05/26/2023, 3:45 AM
Curious what you’ve seen from gRPC Java with respect to this?
I haven't really dug into it, I was expecting to get some exception with the status and associated message, but I got an IO exception stating that the Protobuf message could not be parsed. It might be due to some interceptor needing to be setup, but I expected this behaviour out of the box and it looks like it ignores the status.
y

Yu Xie

05/26/2023, 5:58 PM
Do we not support expecting grpc error code today in the contract?