Kotlin / kotlinx-rpc

Add asynchronous RPC services to your multiplatform applications.
https://kotlin.github.io/kotlinx-rpc/
Apache License 2.0
729 stars 16 forks source link

Exception handling and transport of exceptions #213

Open joseffilzmaier opened 2 weeks ago

joseffilzmaier commented 2 weeks ago

Hey there, thank you for the library, it's looking really neat!

Client target: Android Server target: JVM

I am using the default RPC implementation (i think it's called kRPC) and have have a few remarks/questions regarding exceptions/error handling: Right now, if i make a request from the client and the server throws an exception, the whole whole exception, stacktrace inclusive, is being transferred to the client.

I have a few issues with this approach:

Are there any plans on improving remote exception handling, or am i missing some information here?

Mr3zee commented 2 weeks ago

Hey! Thank you for the feedback! We are working on the improved exception handling and we'll take this into account!

Rattlyy commented 3 days ago

I suggest you try using runCatching {} and return Result<> classes instead

lsafer-meemer commented 3 days ago

I suggest you try using runCatching {} and return Result<> classes instead

Are Result classes serializable? and if so, how could we guarantee that the class of the exception thrown exists at the client?

The true solution for this issue would either be "either" from arrow-kt with the EitherSerializer added to the serializers module:

val CustomSerializersModule = SerializersModule {
    contextual(Either::class) { (leftSerializer, rightSerializer) ->
        EitherSerializer(leftSerializer, rightSerializer)
    }
}

Or union types when they come someday: https://youtrack.jetbrains.com/issue/KT-68296/Union-Types-for-Errors