grpc-errors icon indicating copy to clipboard operation
grpc-errors copied to clipboard

Is it possible to extract extended gRPC details from Python exception?

Open rdmoore opened this issue 4 years ago • 1 comments

I am trying to extract the "details" portion of a gRPC error using Python as the client language. The core protobuf definition that I am basing the behavior on is documented here. Example client code block:

    try:
       response = client.Create(req, timeout=30)
       print(response)
    except grpc._channel._InactiveRpcError as e:
           print("caught as inactive RPC error")
           print(e.__class__)
           print(e.details.__class__)
           print(e.details)

I was expected the details to be the extended content rather than the error message. Am I overlooking something obvious? Is this not supported in the Python client library?

The server-side code is written in go and looks something like this:

		s := status.New(codes.AlreadyExists, "dataset already exists for combination of subject and provenance")
		if s, err = s.WithDetails(res.VersionSets[0]); err != nil {
			logrus.Panicf("cannot add details to google.rpc.Status: %+v", err)
		}
		return nil, s.Err()

rdmoore avatar Oct 11 '21 13:10 rdmoore

Hey! So I am actually working on adding details part of errors, it is work in progress. However you are in luck, since I have added python code samples - https://github.com/avinassh/grpc-errors/pull/15

Hope this helps

avinassh avatar Oct 11 '21 13:10 avinassh