Cannot catch Exception from Server Stub
See original GitHub issueI am attempting to install a default Exception handler for our gRPC server stubs. I have tried using both a java gRPC interceptor and coroutine exception handlers, but nothing seems to work. The following code snippet below replicates the issue.
val handler = CoroutineExceptionHandler { _, ex ->
println("this never happens!!")
}
internal class TestGreeterGrpcService : GreeterGrpcKt.GreeterCoroutineImplBase(handler) {
override suspend fun sayHello(request: HelloRequest): HelloReply = throw RuntimeException("boom")
}
Using the debugger I traced the issue to here
It seems like the CoroutineContext provided to the stub is not used in the Flow that dispatches requests.
I’m fairly new to coroutines so maybe I’m doing something wrong.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:6
Top Results From Across the Web
java - I can't throw NoRouteToHostException even with catch ...
You are not throwing any exceptions. You are catching all of them, then printing the stack and returning false.
Read more >gRPC Error Handling | Vinsguru
Learn gRPC Error Handling with Java. Different options to respond with client when some error occurred using Status, metadata & oneof.
Read more >StubNotFoundException - server program unable to load stub ...
I want to use dynamic code loading. Therefore, I've placed the stub class file in a direcotry accessible by the web server.
Read more >Error Handling in gRPC - Baeldung
All client or server gRPC libraries support the official gRPC error model. Java encapsulates this error model with the class io.grpc.Status.
Read more >Getting Error Handling right in gRPC - Techdozo
The responsibility of the client application (Product Gateway Service) is to call the server application and convert the received response to ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jonpeterson Thanks for sharing that! I was trying to use
onHalfClose
etc and finding they did nothing.In the implementation you shared, is the
LoggingServerCallListener
superfluous? It’s what you’d want ingrpc-java
, right, but exceptions never show up in it ingrpc-kotlin
? So I think this would suffice:I got really stuck on this as well and was about to switch to grpc-java, but then saw how
TransmitStatusRuntimeExceptionInterceptor
implemented a customServerCall
. I’m going to post my solution here to help anyone who comes across this in the future. There are some custom exceptions and extension functions (ex.getLogPrefix
for request and caller ID tracing) that I’m using in my project, but I’ll leave them in just to give an idea of what I was getting at.