grpc-kotlin icon indicating copy to clipboard operation
grpc-kotlin copied to clipboard

Forced StatusException conversion in ClientCalls.onClose()

Open bong01 opened this issue 9 months ago • 0 comments
trafficstars

https://github.com/grpc/grpc-kotlin/blob/a969a91ca37867fa28d83fca234a2b4ced7b1540/stub/src/main/java/io/grpc/kotlin/ClientCalls.kt#L295

In the current implementation of ClientCalls.onClose(), when a response from the server is not isOk and the exception is not a CancellationException, it forcibly converts any exception to StatusException (checked exception) before passing it to responses.close(). While Kotlin doesn't enforce checked exception handling, I'm curious if this conversion is intentional, especially in cases where the original exception is StatusRuntimeException.

Current behavior:

val cause = when {
    status.isOk -> null
    status.cause is CancellationException -> status.cause
    else -> status.asException(trailersMetadata)  // Always converts to StatusException
}

bong01 avatar Feb 08 '25 23:02 bong01