Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throw grpc failed instead of invalid op on generic failure #7861

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
throw grpc failed instead of invalid op on generic failure
  • Loading branch information
apolcyn committed Aug 24, 2016
commit 699743deba09d1965e03ee65661b66f83838a247
3 changes: 1 addition & 2 deletions src/csharp/Grpc.Core.Tests/Internal/AsyncCallServerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ public void WriteCompletionFailureThrows()

var writeTask = responseStream.WriteAsync("request1");
fakeCall.SendCompletionHandler(false);
// TODO(jtattermusch): should we throw a different exception type instead?
Assert.ThrowsAsync(typeof(InvalidOperationException), async () => await writeTask);
Assert.ThrowsAsync(typeof(GrpcOperationFailedException), async () => await writeTask);

fakeCall.ReceivedCloseOnServerHandler(true, cancelled: true);
AssertFinished(asyncCallServer, fakeCall, finishedTask);
Expand Down
3 changes: 1 addition & 2 deletions src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ public void ClientStreaming_WriteCompletionFailure()

var writeTask = requestStream.WriteAsync("request1");
fakeCall.SendCompletionHandler(false);
// TODO: maybe IOException or waiting for RPCException is more appropriate here.
Assert.ThrowsAsync(typeof(InvalidOperationException), async () => await writeTask);
Assert.ThrowsAsync(typeof(GrpcOperationFailedException), async () => await writeTask);

fakeCall.UnaryResponseClientHandler(true,
CreateClientSideStatus(StatusCode.Internal),
Expand Down
1 change: 1 addition & 0 deletions src/csharp/Grpc.Core/Grpc.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<Compile Include="Internal\CallError.cs" />
<Compile Include="Logging\LogLevel.cs" />
<Compile Include="Logging\LogLevelFilterLogger.cs" />
<Compile Include="GrpcOperationFailedException.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Grpc.Core.nuspec" />
Expand Down
19 changes: 19 additions & 0 deletions src/csharp/Grpc.Core/GrpcOperationFailedException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
namespace Grpc.Core
{
public class GrpcOperationFailedException : InvalidOperationException
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FTR, we actually uses to have a similar exception type in a way earlier version of gRPC C# (pre-alpha), but then got rid of it.

{
public GrpcOperationFailedException()
{
}

public GrpcOperationFailedException(string message) : base(message)
{
}

public GrpcOperationFailedException(string message, Exception inner) : base(message, inner)
{
}
}
}

5 changes: 2 additions & 3 deletions src/csharp/Grpc.Core/Internal/AsyncCallBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ protected Exception TryDeserialize(byte[] payload, out TRead msg)
{
try
{

msg = deserializer(payload);
return null;

Expand Down Expand Up @@ -263,7 +262,7 @@ protected void HandleSendFinished(bool success)

if (!success)
{
origTcs.SetException(new InvalidOperationException("Send failed"));
origTcs.SetException(new GrpcOperationFailedException("Send failed"));
}
else
{
Expand All @@ -283,7 +282,7 @@ protected void HandleSendStatusFromServerFinished(bool success)

if (!success)
{
sendStatusFromServerTcs.SetException(new InvalidOperationException("Error sending status from server."));
sendStatusFromServerTcs.SetException(new GrpcOperationFailedException("Error sending status from server."));
}
else
{
Expand Down