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 {
|
try {
|
||||||
return credentials.getRequestMetadata(uri);
|
return credentials.getRequestMetadata(uri);
|
||||||
} catch (IOException e) {
|
} 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) {
|
&& status.getCause() == cancellationCause) {
|
||||||
// If fromThrowable could not determine a status, then
|
// If fromThrowable could not determine a status, then
|
||||||
// just return CANCELLED.
|
// just return CANCELLED.
|
||||||
return Status.CANCELLED.withCause(cancellationCause);
|
return Status.CANCELLED.withDescription("Context cancelled").withCause(cancellationCause);
|
||||||
}
|
}
|
||||||
return status.withCause(cancellationCause);
|
return status.withCause(cancellationCause);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -245,7 +245,8 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stream = new FailingClientStream(DEADLINE_EXCEEDED);
|
stream = new FailingClientStream(
|
||||||
|
DEADLINE_EXCEEDED.withDescription("deadline exceeded: " + effectiveDeadline));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callOptions.getAuthority() != null) {
|
if (callOptions.getAuthority() != null) {
|
||||||
|
|
@ -398,6 +399,8 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT> {
|
||||||
Status status = Status.CANCELLED;
|
Status status = Status.CANCELLED;
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
status = status.withDescription(message);
|
status = status.withDescription(message);
|
||||||
|
} else {
|
||||||
|
status = status.withDescription("Call cancelled without message");
|
||||||
}
|
}
|
||||||
if (cause != null) {
|
if (cause != null) {
|
||||||
status = status.withCause(cause);
|
status = status.withCause(cause);
|
||||||
|
|
@ -433,9 +436,12 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT> {
|
||||||
InputStream messageIs = method.streamRequest(message);
|
InputStream messageIs = method.streamRequest(message);
|
||||||
stream.writeMessage(messageIs);
|
stream.writeMessage(messageIs);
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (RuntimeException e) {
|
||||||
stream.cancel(Status.CANCELLED.withCause(e).withDescription("Failed to stream message"));
|
stream.cancel(Status.CANCELLED.withCause(e).withDescription("Failed to stream message"));
|
||||||
return;
|
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
|
// 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
|
// 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),
|
timerService.schedule(new LogExceptionRunnable(resolutionRunnableOnExecutor),
|
||||||
1, TimeUnit.MINUTES);
|
1, TimeUnit.MINUTES);
|
||||||
}
|
}
|
||||||
savedListener.onError(Status.UNAVAILABLE.withCause(e));
|
savedListener.onError(
|
||||||
|
Status.UNAVAILABLE.withDescription("Unable to resolve host " + host).withCause(e));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Each address forms an EAG
|
// Each address forms an EAG
|
||||||
|
|
|
||||||
|
|
@ -480,7 +480,7 @@ class CronetClientStream extends AbstractClientStream {
|
||||||
} else if (info != null) {
|
} else if (info != null) {
|
||||||
status = toGrpcStatus(info);
|
status = toGrpcStatus(info);
|
||||||
} else {
|
} else {
|
||||||
status = Status.CANCELLED;
|
status = Status.CANCELLED.withDescription("stream cancelled without reason");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finishStream(status);
|
finishStream(status);
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,8 @@ public class ManualFlowControlServer {
|
||||||
}
|
}
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
throwable.printStackTrace();
|
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(
|
address = new InetSocketAddress(
|
||||||
InetAddress.getByAddress(server.getIpAddress().toByteArray()), server.getPort());
|
InetAddress.getByAddress(server.getIpAddress().toByteArray()), server.getPort());
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
propagateError(Status.UNAVAILABLE.withCause(e));
|
propagateError(
|
||||||
|
Status.UNAVAILABLE
|
||||||
|
.withDescription("Host for server not found: " + server)
|
||||||
|
.withCause(e));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
EquivalentAddressGroup eag = new EquivalentAddressGroup(address);
|
EquivalentAddressGroup eag = new EquivalentAddressGroup(address);
|
||||||
|
|
|
||||||
|
|
@ -160,13 +160,13 @@ class Utils {
|
||||||
// look.
|
// look.
|
||||||
ClosedChannelException extraT = new ClosedChannelException();
|
ClosedChannelException extraT = new ClosedChannelException();
|
||||||
extraT.initCause(t);
|
extraT.initCause(t);
|
||||||
return Status.UNKNOWN.withCause(extraT);
|
return Status.UNKNOWN.withDescription("channel closed").withCause(extraT);
|
||||||
}
|
}
|
||||||
if (t instanceof IOException) {
|
if (t instanceof IOException) {
|
||||||
return Status.UNAVAILABLE.withCause(t);
|
return Status.UNAVAILABLE.withDescription("io exception").withCause(t);
|
||||||
}
|
}
|
||||||
if (t instanceof Http2Exception) {
|
if (t instanceof Http2Exception) {
|
||||||
return Status.INTERNAL.withCause(t);
|
return Status.INTERNAL.withDescription("http2 exception").withCause(t);
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ package io.grpc.netty;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertSame;
|
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.Metadata;
|
||||||
import io.grpc.Status;
|
import io.grpc.Status;
|
||||||
import io.grpc.internal.GrpcUtil;
|
import io.grpc.internal.GrpcUtil;
|
||||||
|
|
@ -118,7 +120,8 @@ public class UtilsTest {
|
||||||
|
|
||||||
private static void assertStatusEquals(Status expected, Status actual) {
|
private static void assertStatusEquals(Status expected, Status actual) {
|
||||||
assertEquals(expected.getCode(), actual.getCode());
|
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());
|
assertEquals(expected.getCause(), actual.getCause());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -895,7 +895,10 @@ class OkHttpClientTransport implements ConnectionClientTransport {
|
||||||
Status.UNAVAILABLE.withDescription("End of stream or IOException"));
|
Status.UNAVAILABLE.withDescription("End of stream or IOException"));
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
// TODO(madongfly): Send the exception message to the server.
|
// 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 {
|
} finally {
|
||||||
try {
|
try {
|
||||||
frameReader.close();
|
frameReader.close();
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,10 @@ public final class ProtoReflectionService extends ServerReflectionGrpc.ServerRef
|
||||||
listServices(request);
|
listServices(request);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sendErrorResponse(request, Status.UNIMPLEMENTED, "");
|
sendErrorResponse(
|
||||||
|
request,
|
||||||
|
Status.Code.UNIMPLEMENTED,
|
||||||
|
"not implemented " + request.getMessageRequestCase());
|
||||||
}
|
}
|
||||||
request = null;
|
request = null;
|
||||||
if (closeAfterSend) {
|
if (closeAfterSend) {
|
||||||
|
|
@ -219,7 +222,7 @@ public final class ProtoReflectionService extends ServerReflectionGrpc.ServerRef
|
||||||
if (fd != null) {
|
if (fd != null) {
|
||||||
serverCallStreamObserver.onNext(createServerReflectionResponse(request, fd));
|
serverCallStreamObserver.onNext(createServerReflectionResponse(request, fd));
|
||||||
} else {
|
} 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) {
|
if (fd != null) {
|
||||||
serverCallStreamObserver.onNext(createServerReflectionResponse(request, fd));
|
serverCallStreamObserver.onNext(createServerReflectionResponse(request, fd));
|
||||||
} else {
|
} 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) {
|
if (fd != null) {
|
||||||
serverCallStreamObserver.onNext(createServerReflectionResponse(request, fd));
|
serverCallStreamObserver.onNext(createServerReflectionResponse(request, fd));
|
||||||
} else {
|
} 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)
|
.setAllExtensionNumbersResponse(builder)
|
||||||
.build());
|
.build());
|
||||||
} else {
|
} 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());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendErrorResponse(ServerReflectionRequest request, Status status, String message) {
|
private void sendErrorResponse(
|
||||||
|
ServerReflectionRequest request, Status.Code code, String message) {
|
||||||
ServerReflectionResponse response =
|
ServerReflectionResponse response =
|
||||||
ServerReflectionResponse.newBuilder()
|
ServerReflectionResponse.newBuilder()
|
||||||
.setValidHost(request.getHost())
|
.setValidHost(request.getHost())
|
||||||
.setOriginalRequest(request)
|
.setOriginalRequest(request)
|
||||||
.setErrorResponse(
|
.setErrorResponse(
|
||||||
ErrorResponse.newBuilder()
|
ErrorResponse.newBuilder()
|
||||||
.setErrorCode(status.getCode().value())
|
.setErrorCode(code.value())
|
||||||
.setErrorMessage(message))
|
.setErrorMessage(message))
|
||||||
.build();
|
.build();
|
||||||
serverCallStreamObserver.onNext(response);
|
serverCallStreamObserver.onNext(response);
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,8 @@ final class HealthServiceImpl extends HealthGrpc.HealthImplBase {
|
||||||
StreamObserver<HealthCheckResponse> responseObserver) {
|
StreamObserver<HealthCheckResponse> responseObserver) {
|
||||||
ServingStatus status = getStatus(request.getService());
|
ServingStatus status = getStatus(request.getService());
|
||||||
if (status == null) {
|
if (status == null) {
|
||||||
responseObserver.onError(new StatusException(Status.NOT_FOUND));
|
responseObserver.onError(new StatusException(
|
||||||
|
Status.NOT_FOUND.withDescription("unknown service " + request.getService())));
|
||||||
} else {
|
} else {
|
||||||
HealthCheckResponse response = HealthCheckResponse.newBuilder().setStatus(status).build();
|
HealthCheckResponse response = HealthCheckResponse.newBuilder().setStatus(status).build();
|
||||||
responseObserver.onNext(response);
|
responseObserver.onNext(response);
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ public class HealthStatusManagerTest {
|
||||||
//verify
|
//verify
|
||||||
ArgumentCaptor<StatusException> exception = ArgumentCaptor.forClass(StatusException.class);
|
ArgumentCaptor<StatusException> exception = ArgumentCaptor.forClass(StatusException.class);
|
||||||
verify(observer, times(1)).onError(exception.capture());
|
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();
|
verify(observer, never()).onCompleted();
|
||||||
}
|
}
|
||||||
|
|
@ -107,7 +107,7 @@ public class HealthStatusManagerTest {
|
||||||
//verify
|
//verify
|
||||||
ArgumentCaptor<StatusException> exception = ArgumentCaptor.forClass(StatusException.class);
|
ArgumentCaptor<StatusException> exception = ArgumentCaptor.forClass(StatusException.class);
|
||||||
verify(observer, times(1)).onError(exception.capture());
|
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();
|
verify(observer, never()).onCompleted();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -222,7 +222,8 @@ public final class ClientCalls {
|
||||||
}
|
}
|
||||||
cause = cause.getCause();
|
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();
|
last = waitForNext();
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
throw Status.CANCELLED.withCause(ie).asRuntimeException();
|
throw Status.CANCELLED.withDescription("interrupted").withCause(ie).asRuntimeException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (last instanceof StatusRuntimeException) {
|
if (last instanceof StatusRuntimeException) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue