mirror of https://github.com/grpc/grpc-java.git
all: add Status messages to all statuses
This commit is contained in:
parent
2d88269965
commit
c9b02db276
|
@ -132,7 +132,8 @@ public final class ClientAuthInterceptor implements ClientInterceptor {
|
|||
try {
|
||||
return credentials.getRequestMetadata(uri);
|
||||
} catch (IOException e) {
|
||||
throw Status.UNAUTHENTICATED.withCause(e).asException();
|
||||
throw Status.UNAUTHENTICATED.withDescription("Unable to get request metadata").withCause(e)
|
||||
.asException();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ public final class Contexts {
|
|||
&& status.getCause() == cancellationCause) {
|
||||
// If fromThrowable could not determine a status, then
|
||||
// just return CANCELLED.
|
||||
return Status.CANCELLED.withCause(cancellationCause);
|
||||
return Status.CANCELLED.withDescription("Context cancelled").withCause(cancellationCause);
|
||||
}
|
||||
return status.withCause(cancellationCause);
|
||||
}
|
||||
|
|
|
@ -245,7 +245,8 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT> {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
stream = new FailingClientStream(DEADLINE_EXCEEDED);
|
||||
stream = new FailingClientStream(
|
||||
DEADLINE_EXCEEDED.withDescription("deadline exceeded: " + effectiveDeadline));
|
||||
}
|
||||
|
||||
if (callOptions.getAuthority() != null) {
|
||||
|
@ -398,6 +399,8 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT> {
|
|||
Status status = Status.CANCELLED;
|
||||
if (message != null) {
|
||||
status = status.withDescription(message);
|
||||
} else {
|
||||
status = status.withDescription("Call cancelled without message");
|
||||
}
|
||||
if (cause != null) {
|
||||
status = status.withCause(cause);
|
||||
|
@ -433,9 +436,12 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT> {
|
|||
InputStream messageIs = method.streamRequest(message);
|
||||
stream.writeMessage(messageIs);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
} catch (RuntimeException e) {
|
||||
stream.cancel(Status.CANCELLED.withCause(e).withDescription("Failed to stream message"));
|
||||
return;
|
||||
} catch (Error e) {
|
||||
stream.cancel(Status.CANCELLED.withDescription("Client sendMessage() failed with Error"));
|
||||
throw e;
|
||||
}
|
||||
// For unary requests, we don't flush since we know that halfClose should be coming soon. This
|
||||
// allows us to piggy-back the END_STREAM=true on the last message frame without opening the
|
||||
|
|
|
@ -169,7 +169,8 @@ final class DnsNameResolver extends NameResolver {
|
|||
timerService.schedule(new LogExceptionRunnable(resolutionRunnableOnExecutor),
|
||||
1, TimeUnit.MINUTES);
|
||||
}
|
||||
savedListener.onError(Status.UNAVAILABLE.withCause(e));
|
||||
savedListener.onError(
|
||||
Status.UNAVAILABLE.withDescription("Unable to resolve host " + host).withCause(e));
|
||||
return;
|
||||
}
|
||||
// Each address forms an EAG
|
||||
|
|
|
@ -480,7 +480,7 @@ class CronetClientStream extends AbstractClientStream {
|
|||
} else if (info != null) {
|
||||
status = toGrpcStatus(info);
|
||||
} else {
|
||||
status = Status.CANCELLED;
|
||||
status = Status.CANCELLED.withDescription("stream cancelled without reason");
|
||||
}
|
||||
}
|
||||
finishStream(status);
|
||||
|
|
|
@ -101,7 +101,8 @@ public class ManualFlowControlServer {
|
|||
}
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
responseObserver.onError(Status.UNKNOWN.withCause(throwable).asException());
|
||||
responseObserver.onError(
|
||||
Status.UNKNOWN.withDescription("Error handling request").withCause(throwable).asException());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -530,7 +530,10 @@ final class GrpclbState {
|
|||
address = new InetSocketAddress(
|
||||
InetAddress.getByAddress(server.getIpAddress().toByteArray()), server.getPort());
|
||||
} catch (UnknownHostException e) {
|
||||
propagateError(Status.UNAVAILABLE.withCause(e));
|
||||
propagateError(
|
||||
Status.UNAVAILABLE
|
||||
.withDescription("Host for server not found: " + server)
|
||||
.withCause(e));
|
||||
continue;
|
||||
}
|
||||
EquivalentAddressGroup eag = new EquivalentAddressGroup(address);
|
||||
|
|
|
@ -160,13 +160,13 @@ class Utils {
|
|||
// look.
|
||||
ClosedChannelException extraT = new ClosedChannelException();
|
||||
extraT.initCause(t);
|
||||
return Status.UNKNOWN.withCause(extraT);
|
||||
return Status.UNKNOWN.withDescription("channel closed").withCause(extraT);
|
||||
}
|
||||
if (t instanceof IOException) {
|
||||
return Status.UNAVAILABLE.withCause(t);
|
||||
return Status.UNAVAILABLE.withDescription("io exception").withCause(t);
|
||||
}
|
||||
if (t instanceof Http2Exception) {
|
||||
return Status.INTERNAL.withCause(t);
|
||||
return Status.INTERNAL.withDescription("http2 exception").withCause(t);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ package io.grpc.netty;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.truth.Truth;
|
||||
import io.grpc.Metadata;
|
||||
import io.grpc.Status;
|
||||
import io.grpc.internal.GrpcUtil;
|
||||
|
@ -118,7 +120,8 @@ public class UtilsTest {
|
|||
|
||||
private static void assertStatusEquals(Status expected, Status actual) {
|
||||
assertEquals(expected.getCode(), actual.getCode());
|
||||
assertEquals(expected.getDescription(), actual.getDescription());
|
||||
Truth.assertThat(MoreObjects.firstNonNull(actual.getDescription(), ""))
|
||||
.contains(MoreObjects.firstNonNull(expected.getDescription(), ""));
|
||||
assertEquals(expected.getCause(), actual.getCause());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -895,7 +895,10 @@ class OkHttpClientTransport implements ConnectionClientTransport {
|
|||
Status.UNAVAILABLE.withDescription("End of stream or IOException"));
|
||||
} catch (Throwable t) {
|
||||
// TODO(madongfly): Send the exception message to the server.
|
||||
startGoAway(0, ErrorCode.PROTOCOL_ERROR, Status.UNAVAILABLE.withCause(t));
|
||||
startGoAway(
|
||||
0,
|
||||
ErrorCode.PROTOCOL_ERROR,
|
||||
Status.UNAVAILABLE.withDescription("error in frame handler").withCause(t));
|
||||
} finally {
|
||||
try {
|
||||
frameReader.close();
|
||||
|
|
|
@ -188,7 +188,10 @@ public final class ProtoReflectionService extends ServerReflectionGrpc.ServerRef
|
|||
listServices(request);
|
||||
break;
|
||||
default:
|
||||
sendErrorResponse(request, Status.UNIMPLEMENTED, "");
|
||||
sendErrorResponse(
|
||||
request,
|
||||
Status.Code.UNIMPLEMENTED,
|
||||
"not implemented " + request.getMessageRequestCase());
|
||||
}
|
||||
request = null;
|
||||
if (closeAfterSend) {
|
||||
|
@ -219,7 +222,7 @@ public final class ProtoReflectionService extends ServerReflectionGrpc.ServerRef
|
|||
if (fd != null) {
|
||||
serverCallStreamObserver.onNext(createServerReflectionResponse(request, fd));
|
||||
} else {
|
||||
sendErrorResponse(request, Status.NOT_FOUND, "File not found.");
|
||||
sendErrorResponse(request, Status.Code.NOT_FOUND, "File not found.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -229,7 +232,7 @@ public final class ProtoReflectionService extends ServerReflectionGrpc.ServerRef
|
|||
if (fd != null) {
|
||||
serverCallStreamObserver.onNext(createServerReflectionResponse(request, fd));
|
||||
} else {
|
||||
sendErrorResponse(request, Status.NOT_FOUND, "Symbol not found.");
|
||||
sendErrorResponse(request, Status.Code.NOT_FOUND, "Symbol not found.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -242,7 +245,7 @@ public final class ProtoReflectionService extends ServerReflectionGrpc.ServerRef
|
|||
if (fd != null) {
|
||||
serverCallStreamObserver.onNext(createServerReflectionResponse(request, fd));
|
||||
} else {
|
||||
sendErrorResponse(request, Status.NOT_FOUND, "Extension not found.");
|
||||
sendErrorResponse(request, Status.Code.NOT_FOUND, "Extension not found.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -261,7 +264,7 @@ public final class ProtoReflectionService extends ServerReflectionGrpc.ServerRef
|
|||
.setAllExtensionNumbersResponse(builder)
|
||||
.build());
|
||||
} else {
|
||||
sendErrorResponse(request, Status.NOT_FOUND, "Type not found.");
|
||||
sendErrorResponse(request, Status.Code.NOT_FOUND, "Type not found.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -278,14 +281,15 @@ public final class ProtoReflectionService extends ServerReflectionGrpc.ServerRef
|
|||
.build());
|
||||
}
|
||||
|
||||
private void sendErrorResponse(ServerReflectionRequest request, Status status, String message) {
|
||||
private void sendErrorResponse(
|
||||
ServerReflectionRequest request, Status.Code code, String message) {
|
||||
ServerReflectionResponse response =
|
||||
ServerReflectionResponse.newBuilder()
|
||||
.setValidHost(request.getHost())
|
||||
.setOriginalRequest(request)
|
||||
.setErrorResponse(
|
||||
ErrorResponse.newBuilder()
|
||||
.setErrorCode(status.getCode().value())
|
||||
.setErrorCode(code.value())
|
||||
.setErrorMessage(message))
|
||||
.build();
|
||||
serverCallStreamObserver.onNext(response);
|
||||
|
|
|
@ -41,7 +41,8 @@ final class HealthServiceImpl extends HealthGrpc.HealthImplBase {
|
|||
StreamObserver<HealthCheckResponse> responseObserver) {
|
||||
ServingStatus status = getStatus(request.getService());
|
||||
if (status == null) {
|
||||
responseObserver.onError(new StatusException(Status.NOT_FOUND));
|
||||
responseObserver.onError(new StatusException(
|
||||
Status.NOT_FOUND.withDescription("unknown service " + request.getService())));
|
||||
} else {
|
||||
HealthCheckResponse response = HealthCheckResponse.newBuilder().setStatus(status).build();
|
||||
responseObserver.onNext(response);
|
||||
|
|
|
@ -86,7 +86,7 @@ public class HealthStatusManagerTest {
|
|||
//verify
|
||||
ArgumentCaptor<StatusException> exception = ArgumentCaptor.forClass(StatusException.class);
|
||||
verify(observer, times(1)).onError(exception.capture());
|
||||
assertEquals(Status.NOT_FOUND, exception.getValue().getStatus());
|
||||
assertEquals(Status.Code.NOT_FOUND, exception.getValue().getStatus().getCode());
|
||||
|
||||
verify(observer, never()).onCompleted();
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ public class HealthStatusManagerTest {
|
|||
//verify
|
||||
ArgumentCaptor<StatusException> exception = ArgumentCaptor.forClass(StatusException.class);
|
||||
verify(observer, times(1)).onError(exception.capture());
|
||||
assertEquals(Status.NOT_FOUND, exception.getValue().getStatus());
|
||||
assertEquals(Status.Code.NOT_FOUND, exception.getValue().getStatus().getCode());
|
||||
|
||||
verify(observer, never()).onCompleted();
|
||||
}
|
||||
|
|
|
@ -222,7 +222,8 @@ public final class ClientCalls {
|
|||
}
|
||||
cause = cause.getCause();
|
||||
}
|
||||
return Status.UNKNOWN.withCause(t).asRuntimeException();
|
||||
return Status.UNKNOWN.withDescription("unexpected exception").withCause(t)
|
||||
.asRuntimeException();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -547,7 +548,7 @@ public final class ClientCalls {
|
|||
last = waitForNext();
|
||||
} catch (InterruptedException ie) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw Status.CANCELLED.withCause(ie).asRuntimeException();
|
||||
throw Status.CANCELLED.withDescription("interrupted").withCause(ie).asRuntimeException();
|
||||
}
|
||||
}
|
||||
if (last instanceof StatusRuntimeException) {
|
||||
|
|
Loading…
Reference in New Issue