Skip to content
Open
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
4 changes: 3 additions & 1 deletion stub/src/main/java/io/grpc/kotlin/ServerCalls.kt
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ object ServerCalls {
null -> Status.OK
is CancellationException -> Status.CANCELLED.withCause(failure)
is StatusException, is StatusRuntimeException -> Status.fromThrowable(failure)
else -> Status.fromThrowable(failure).withCause(failure)
else -> Status.UNKNOWN
.withDescription("Unknown Exception")
.withCause(failure)
}
val trailers = failure?.let { Status.trailersFromThrowable(it) } ?: GrpcMetadata()
mutex.withLock { call.close(closeStatus, trailers) }
Expand Down
14 changes: 8 additions & 6 deletions stub/src/test/java/io/grpc/kotlin/ServerCallsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ class ServerCallsTest : AbstractCallsTest() {
}
}

val receivedStatusCause = CompletableDeferred<Throwable?>()
val receivedStatus = CompletableDeferred<Status?>()

val interceptor = object : ServerInterceptor {
override fun <ReqT, RespT> interceptCall(
Expand All @@ -1195,7 +1195,7 @@ class ServerCallsTest : AbstractCallsTest() {
next.startCall(
object : ForwardingServerCall.SimpleForwardingServerCall<ReqT, RespT>(call) {
override fun close(status: Status, trailers: Metadata) {
receivedStatusCause.complete(status.cause)
receivedStatus.complete(status)
super.close(status, trailers)
}
},
Expand All @@ -1213,11 +1213,13 @@ class ServerCallsTest : AbstractCallsTest() {
// the exception should not propagate to the client
assertThat(clientException.cause).isNull()

assertThat(clientException.status.code).isEqualTo(Status.Code.INTERNAL)
val statusCause = receivedStatusCause.await()
assertThat(clientException.status.code).isEqualTo(Status.Code.UNKNOWN)
val status = receivedStatus.await()!!
// but the exception should propagate to server interceptors, with stack trace intact
assertThat(statusCause).isEqualTo(thrownStatusCause.await())
assertThat(statusCause!!.stackTraceToString()).contains("internalServerCall")
assertThat(status.code).isEqualTo(Status.UNKNOWN.code)
assertThat(status.description).isEqualTo("Unknown Exception")
assertThat(status.cause).isEqualTo(thrownStatusCause.await())
assertThat(status.cause?.stackTraceToString()).contains("internalServerCall")
}

}