Answering my own question - 

I am about to build workaround by doing this:

debug_info_any = Google::Protobuf::Any.pack(
 Google::Rpc::DebugInfo.new(
 stack_entries: ["stack_entries 1", "stack_entries 2"],
 )
)
rich_error = Google::Rpc::Status.new(
 code: 1,
 message: 'matching message',
 details: [debug_info_any],
 )
encoded_rich_error = Google::Rpc::Status.encode(rich_error)
raise GRPC::BadStatus.new(
 GRPC::Core::StatusCodes::INVALID_ARGUMENT,
 "invalid argument msg",
 'grpc-status-details-bin' => encoded_rich_error)


But I still wonder if there's a better approach in Ruby. Thanks!


On Tuesday, January 14, 2020 at 4:08:24 PM UTC-8, Juanyi Feng wrote:
>
> According to gRPC Error Handing <https://grpc.io/docs/guides/error/>, Richer 
> error model contains much more information than the standard one comes with 
> gRPC default. So I decided to use it for my gRPC servers for Errors.
>
> In Java, I am able to easily use it and return Error in response as 
>
> Status status = Status.newBuilder()
>         .setCode(Code.INVALID_ARGUMENT.getNumber())
>         .setMessage("Required argument is empty.")
>         .addDetails(Any.pack(DebugInfo.newBuilder().addStackEntries("This 
> is a sample stack trace").build()))
>         .build();
>       
> responseObserver.onError(StatusProto.toStatusRuntimeException(status));
>
> However, I also have gRPC servers which are written in Ruby. And I can't 
> find a way to raise an exception or return error status as in Java.
>
> I did this:
>
>     debug_info = Google::Rpc::DebugInfo.new(
>       stack_entries: ["1", "2"] ,
>     )
>
>     error_status = Google::Rpc::Status.new(
>       code: 3,
>       message: "msg",
>       details: [Google::Protobuf::Any.pack(debug_info)]
>     )
> # no way for me to throw exception from error_status
>
> After i initialized a Google::Rpc::Status instance, it seems like there is 
> no way for me to raise an exception from error_status I created. Anyone has 
> any idea how I can do it in Ruby? 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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/68a0f27a-6cd2-4474-b589-0693e4c9b43f%40googlegroups.com.

Reply via email to