elixir-protobuf / protobuf

A pure Elixir implementation of Google Protobuf.
https://hexdocs.pm/protobuf/readme.html
MIT License
823 stars 143 forks source link

Feature Request: support google.rpc.Status.Details #64

Closed joelmarty closed 5 years ago

joelmarty commented 5 years ago

The gRPC error model has the ability to embed any kind of message in the status of a RPC (see this doc).

It is a feature that would be quite useful to convey error details since custom status codes are not documented in .proto files.

tony612 commented 5 years ago

google's protos are just normal protobuf. You can directly use them after generating the code.

iex(2)> Google.Rpc.Status.new(details: [%{type_url: "foo", value: "Custom error"}])
%Google.Rpc.Status{
  code: 0,
  details: [%Google.Protobuf.Any{type_url: "foo", value: "Custom error"}],
  message: ""
}

If I misunderstand your question, please let me know.

joelmarty commented 5 years ago

What I mean is that if a server returns a status with details, the lib does not exposes it. In my test case I have a server (in go) that does the following:

status.New(codes.Code(customerror.Error_NOT_FOUND), "broken").WithDetails(ptypes.TimestampNow())

With that use case, a client in Go is able to read and extract the timestamp embedded in the status' details. But with an elixir client using your library and considering the following code:

try do
      channel = GrpcElixirTest.connect(opts[:host], rpc_opts)
      GrpcElixirTest.get_something(channel, "")
      |> Enum.map_join("\n", fn {key, val} -> ~s{"#{key}", "#{val}"} end)
      |> IO.puts
rescue
      e in GRPC.RPCError -> IO.puts("#{inspect e}")

will print:

%GRPC.RPCError{message: "broken", status: 123}

So the details are not exposed, and if it somehow possible to extract them, it is not documented

tony612 commented 5 years ago

I see. So it should be a feature request for gRPC. Now grpc doesn't support returning errors when got an error. Let's address this problem in this issue https://github.com/elixir-grpc/grpc/issues/109