Attach error details to status in Ruby

32 views
Skip to first unread message

Connor Taffe

unread,
Aug 6, 2019, 3:26:43 PM8/6/19
to grpc.io
At work we're standardizing on using the Richer Error Model and had success using it in Go with the errdetails package and WithDetails method. However, we also write a lot of Ruby. In Ruby, it's not documented how you would attach details to the status. Is it possible to attach error details using the error classes e.g. GRPC::InvalidArgument? If not, is it possible to write my own error classes which would allow attaching details?

For example perhaps I can create an API like this?
raise GRPC::InvalidArgument.new(
 
"foo.bar must only contain alphanumeric characters",
 
details: Google::Rpc::BadRequest.new(
   
field_violations: [
     
Google::Rpc::BadRequest::FieldViolation.new(
       
field: "foo.bar",
       
description: "must only contain alphanumeric characters"
     
)
   
]
 
)
)



apo...@google.com

unread,
Jul 24, 2020, 3:56:41 PM7/24/20
to grpc.io
There isn't currently a convenience API for doing this at the Ruby server but it is possible, by doing something like what is done in this test server: https://github.com/grpc/grpc/blob/fa02ab8d3fc961f8a155412655c21a9659efa29d/src/ruby/spec/google_rpc_status_utils_spec.rb#L128

I.e., you can create a Google::Rpc::Status protobuf, and then pack the serialized version of it into status details, as in https://github.com/grpc/grpc/blob/fa02ab8d3fc961f8a155412655c21a9659efa29d/src/ruby/spec/google_rpc_status_utils_spec.rb#L135.

Does that help?
Reply all
Reply to author
Forward
0 new messages