-
Notifications
You must be signed in to change notification settings - Fork 434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GRpcExceptionHandler doesn't work [Kotlin] #268
Comments
@jvmlet |
for unary call it's called from here |
Ohh, I think the issue is this line , I should also check the |
Meanwhile, please add dummy global handler as temporary workaround to proceed here .. |
Please tell, is code ok? Exception class TestException(message: String) : Exception(message) Service @GRpcService
class FileService() : FileServiceGrpcKt.FileServiceCoroutineImplBase() {
override suspend fun getInfo(request: FileInfoRequest): FileInfoResponse {
throw TestException("Hello")
}
} Advice @GRpcServiceAdvice
class GRpcErrorInterceptor {
private val logger = KotlinLogging.logger {}
@GRpcExceptionHandler
fun throwableExceptionHandler(e: TestException, scope: GRpcExceptionScope): Status {
logger.error(e) { "gRPC unexpected error" }
return Status.INTERNAL.withCause(e) // should be code 13
}
} But no logs in application, and status differs: hett@STORM:~ $ grpc_cli call 172.23.0.1:9090 getInfo ""
connecting to 172.23.0.1:9090
Rpc failed with status code 2, error message: I can provide demo app. |
Hmmm, I suspected that the problem is in the coroutines, but not. This doesn't work too: @GRpcService()
class FileService() : FileServiceGrpc.FileServiceImplBase() {
private val logger = KotlinLogging.logger {}
override fun getInfo(request: FileInfoRequest, responseObserver: StreamObserver<FileInfoResponse>) {
throw TestException("Hello")
}
} |
You should have both |
You also should wrap your exception with |
Bingo, with runtime exception it is works! If declared next exception, no any logs will produced on error and it big problem: class TestException(message: String) : java.lang.Exception(message) The next code with runtime exception works (global handler registered too): class TestException(message: String) : java.lang.RuntimeException(message) @GRpcService()
class FileService() : FileServiceGrpc.FileServiceImplBase() {
@GRpcExceptionHandler
fun anotherHandler(e: TestException, scope: GRpcExceptionScope): Status {
logger.warn { "error!" }
return Status.INTERNAL
}
override fun getInfo(request: FileInfoRequest, responseObserver: StreamObserver<FileInfoResponse>) {
throw TestException("Hello")
}
} But if trying to extend kotlin corutine impl we get silence again in the logs :( @GRpcService()
class FileService() : FileServiceGrpcKt.FileServiceCoroutineImplBase() {
@GRpcExceptionHandler
fun anotherHandler(e: TestException, scope: GRpcExceptionScope): Status {
logger.warn { "error!" }
return Status.INTERNAL
}
override suspend fun getInfo(request: FileInfoRequest): FileInfoResponse {
throw TestException("Hello")
}
} I suspect that it is different troubles. |
I created demo project which reproduces both problems https://github.com/TheHett/grpc_demo/tree/master/src/main/kotlin/com/example/demo/grpc It should be call manually because I doesn't know how to write test for this
|
You can have a look at demo module in this repo to get the idea how to develop unit tests |
Hi, It doesn't works for me as for @TheHett. I have checked At runtime, when I look at this condition for check global exception handler (declared via Ps: for test with exception, i did used the @jvmlet have you an idea about how I could work around this issue please ? |
Any idea @jvmlet please ? |
i have the same problem with kotlin, @GrpcExceptionHandler in service or @GRpcServiceAdvice on single class doesn't work |
Still relevant with 4.9.1, any updates here? |
Fixed in latest |
|
I am still getting it in Maybe it's somehow interfere with the order of interceptors?
|
Hi, thanks for the work you've done. It's really great starter!
I have some trouble, maybe it related with Kotlin CoroutineImpl.
The interceptor below does not catch exception:
Using 4.5.10 version.
The text was updated successfully, but these errors were encountered: