question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RpcException seems to put inner exception details in the exception message but leaves InnerException property as null

See original GitHub issue

When making a grpc call, I am trying to provide user friendly messages when the server address is not reachable or the connection times out.

However, in both cases the rpc exception returns status code of “Unavailable”, and the HResult property has the same value. I tried to read the InnerException property to help distinguish between the two cases, but found that the property is null.

The only information I have right now is in the exception Message property, where the HttpRequestException message is appended. For example:

Status(StatusCode="Unavailable", Detail="Error starting gRPC call. HttpRequestException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (192.168.132.127:64873) SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.", DebugException="System.Net.Http.HttpRequestException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (192.168.132.127:64873)
 ---> System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|277_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.AddHttp2ConnectionAsync(HttpRequestMessage request)
   at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.GetHttp2ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at Grpc.Net.Client.Internal.GrpcCall`2.RunCall(HttpRequestMessage request, Nullable`1 timeout)")

So right now it seems I have to parse the exception message to know the exact reason of the RpcException. However, HttpRequestException.Message is localized and makes it unsuitable for parsing if not in English language.

Is it possible to assign the caught HttpRequestException into the RpcException.InnerException? Having access to the inner HttpRequestException will allow me to programmatically determine the reason of the exception. For example, in the case of a connection time out, the HttpRequestException caught has InnerException of SocketException which has a property SocketErrorCode of Timeout.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JamesNKcommented, Jun 20, 2022

You can access the exception via RpcException.Status.DebugException.

0reactions
JamesNKcommented, Jun 20, 2022

If it’s removed then it will be marked as obsolete for a long time before then to give people a chance to react.

Read more comments on GitHub >

github_iconTop Results From Across the Web

When gRPC client throws RpcException on a method, how ...
The inner exception is null and only way to find the exception was to parse the error message -- not as reliable as...
Read more >
Exception.InnerException Property (System)
The InnerException property returns the same value as was passed into the Exception(String, Exception) constructor, or null if the inner exception value was...
Read more >
Inspect an exception using the Exception Helper
You can inspect and view properties of the Exception object by clicking the View Details link. Analyze null references. Starting in Visual ...
Read more >
Inner Exception in C# with Examples
In this article, I am going to discuss Inner Exception in C# with Examples. Inner Exception is a property that returns the Exception...
Read more >
How to Serialize Exceptions as JSON in .NET
Demonstrate how to serialize exceptions in .NET with elaborate explanation, guidelines and practical examples.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found