Communicating Rich Error Detail in C#

456 views
Skip to first unread message

Aggarwal Sre

unread,
Mar 29, 2021, 4:33:03 PM3/29/21
to grpc.io
Hi GRPC group,

I am trying to see what is the best way to communicate rich error information from a Server written in C# to various clients.

Rich error model is currently not supported in C#. Also, passing the information via Trailers comes with various caveats listed here : Error handling | gRPC

I also noticed that Status has an *Experimental* constructor which takes in exception. 

Is there a plan to make this constructor supported in future versions. As it is not intended to be used, so it is not totally clear how this fits in. 

Above being said, what is the recommended/best way to communicate rich error information from a c# server.

I look forward to a response. Thanks in advance. 

Regards,
Vivek



Christopher Warrington - MSFT

unread,
Mar 30, 2021, 12:56:36 AM3/30/21
to grpc.io
On Monday, March 29, 2021 at 1:33:03 PM UTC-7 Vivek wrote:

> Rich error model is currently not supported in C#.

While there's nothing built-in to either gRPC C# or gRPC.NET (yet?), you can
implement it manually. I have a fully working gRPC.NET example at
https://github.com/chwarr/grpc-dotnet-google-rpc-status.

--
Christopher Warrington
Microsoft Corp.

Aggarwal Sre

unread,
Mar 30, 2021, 4:00:21 AM3/30/21
to Christopher Warrington - MSFT, grpc.io
Thanks for the response, @Christopher. Yes, I am also doing something similar ( rather using GRPC message, I am using my own message type], but in nut shell I am using the Trailer approach. As I mentioned the Trailer approach comes with some caveats. Hence, I wanted to know if there is a better way to do this esp. Fault Contract approach mentioned here: https://docs.microsoft.com/en-us/dotnet/architecture/grpc-for-wcf-developers/error-handling#grpc-richer-error-model

Regards,
-Vivek

--
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 grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/adcec07d-fb7f-4588-8567-31813a5cef4an%40googlegroups.com.

Christopher Warrington - MSFT

unread,
Mar 31, 2021, 3:41:19 PM3/31/21
to grpc.io
On Tuesday, March 30, 2021 at 1:00:21 AM UTC-7 Vivek wrote:

> As I mentioned the Trailer approach comes with some caveats. Hence, I
> wanted to know if there is a better way to do this esp. Fault Contract
> approach mentioned here:
> https://docs.microsoft.com/en-us/dotnet/architecture/grpc-for-wcf-developers/error-handling#grpc-richer-error-model

No, there is nothing built in to either gRPC or Protocol Buffers for
_explicitly modeling faults_ à la SOAP.

As you've found, there are caveats to the rich error model. Only you can
determine whether this approach will work for your software or not. Whatever
you decide, for the sake of your consumers, please explicitly document it.
And test your error cases. :-)

If you are consuming another gRPC API, you will have to consult its
documentation to determine how it models faults.

I've worked on projects that were able to use the rich error model, as we
could handle the caveats. We controlled all the clients, proxies, and
servers. We had two languages, and we wrote helpers to encode and extract
the rich error information. We taught our custom HTTP monitoring components
how to understand gRPC errors. &c.
Reply all
Reply to author
Forward
0 new messages