avinassh / grpc-errors

A handy guide to gRPC errors
http://avi.im/grpc-errors
MIT License
581 stars 78 forks source link

Adding examples of Status Details in addition to Code and Message? #10

Open tombry opened 6 years ago

tombry commented 6 years ago

Theses examples are great! I wish that the grpc project would fold them into the standard language quick start or tutorials.

I see that the examples seem to focus on setting the error code and message, but the Status now supports additional details: https://godoc.org/google.golang.org/grpc/status#Status.Details.

Have you considered extending the examples to show how to set and retrieve these details? I'm personally interested in Python and Go at the moment, but I guess you'd want to expand all of the examples at once.

avinassh commented 6 years ago

Does only Go supports this? I can't seem to find much details for other languages.

eyalpost commented 5 years ago

+1 for client\server examples of handling details In Java it is also supported this via:

        Status s = com.google.rpc.Status.newBuilder()
                .setCode(com.google.rpc.Code.INVALID_ARGUMENT.getNumber())
                .setMessage("Invalid age")
                .addDetails(Any.pack(BadRequest.newBuilder()
                                .addFieldViolations(BadRequest.FieldViolation
                                        .newBuilder()
                                        .setField("age")
                                        .setDescription("age must be positive ")
                                        .build()
                                ).build()
                        )
                ).build();

        throw io.grpc.protobuf.StatusProto.toStatusRuntimeException(s);
Ciantic commented 5 years ago

Yes, I would like this for C#, it's really hard to figure out. I guess google.rpc.Status should be inserted in trailers, and embedding e.g. google.rpc.BadRequest inside that.

But no examples anywhere.

I think google.rpc.BadRequest with field violations is so fundamental error type that example of it's usage should be shown.

avinassh commented 4 years ago

Hey!

So, gRPC docs finally added few more details on rich error handling - https://grpc.io/docs/guides/error/#richer-error-model

According to the docs:

This richer error model is already supported in the C++, Go, Java, Python, and Ruby libraries, and at least the grpc-web and Node.js libraries have open issues requesting it.

I have started working on and opened a PR - #15

I have added Go and Python examples for now and other language examples later. If anyone interested doing same for C++, Java or Ruby, please let me know. Thank you!