Blocking calls should error with StatusRuntimeException

Previously, it always threw a RuntimeExecutionException with a
StatusRuntimeException within (since the only callers of setException()
provide a StatusRuntimeException).

Resolves #507
This commit is contained in:
Eric Anderson 2015-06-18 17:49:56 -07:00
parent 4d5caf83fb
commit fd52a765ed
1 changed files with 3 additions and 17 deletions

View File

@ -34,9 +34,7 @@ package io.grpc.stub;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.util.concurrent.AbstractFuture; import com.google.common.util.concurrent.AbstractFuture;
import com.google.common.util.concurrent.ExecutionError;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.UncheckedExecutionException;
import io.grpc.ClientCall; import io.grpc.ClientCall;
import io.grpc.Metadata; import io.grpc.Metadata;
@ -95,10 +93,7 @@ public class ClientCalls {
* *
* @throws RuntimeException if {@code get} is interrupted * @throws RuntimeException if {@code get} is interrupted
* @throws CancellationException if {@code get} throws a {@code CancellationException} * @throws CancellationException if {@code get} throws a {@code CancellationException}
* @throws UncheckedExecutionException if {@code get} throws an {@code ExecutionException} with an * @throws StatusRuntimeException if {@code get} throws an {@code ExecutionException}
* {@code Exception} as its cause
* @throws ExecutionError if {@code get} throws an {@code ExecutionException} with an {@code
* Error} as its cause
*/ */
private static <V> V getUnchecked(Future<V> future) { private static <V> V getUnchecked(Future<V> future) {
try { try {
@ -107,16 +102,7 @@ public class ClientCalls {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (ExecutionException e) { } catch (ExecutionException e) {
if (e.getCause() == null) { throw Status.fromThrowable(e).asRuntimeException();
// Strange...
throw new UncheckedExecutionException(e);
} else {
if (e.getCause() instanceof Error) {
throw new ExecutionError((Error) e.getCause());
} else {
throw new UncheckedExecutionException(e.getCause());
}
}
} }
} }
@ -318,7 +304,7 @@ public class ClientCalls {
// No value received so mark the future as an error // No value received so mark the future as an error
responseFuture.setException( responseFuture.setException(
Status.INTERNAL.withDescription("No value received for unary call") Status.INTERNAL.withDescription("No value received for unary call")
.asRuntimeException().fillInStackTrace()); .asRuntimeException());
} }
responseFuture.set(value); responseFuture.set(value);
} else { } else {