Kermit icon indicating copy to clipboard operation
Kermit copied to clipboard

XcodeSeverityWriter and OSLogWriter should use stackTraceToString

Open kodebach opened this issue 1 year ago • 0 comments

Both XcodeSeverityWriter and OSLogWriter currently use

throwable.getStackTrace().joinToString("\n")

to convert a given Throwable into a loggable String. This works, but it only includes the stack trace for throwable itself. It does not include any of the causes or suppressed exceptions nor the message of throwable.

For example a serialization error in Ktor only shows

at 0   ios_app                             0x108672347        kfun:kotlin.Exception#<init>(kotlin.String?;kotlin.Throwable?){} + 143 
at 1   ios_app                             0x1085fdddf        kfun:io.ktor.serialization.ContentConvertException#<init>(kotlin.String;kotlin.Throwable?){} + 123 
at 2   ios_app                             0x1085fdfa3        kfun:io.ktor.serialization.JsonConvertException#<init>(kotlin.String;kotlin.Throwable?){} + 123 
at 3   ios_app                             0x108601faf        kfun:io.ktor.serialization.kotlinx.KotlinxSerializationConverter.$deserializeCOROUTINE$3.invokeSuspend#internal + 2771 
[...]

Without the message and the cause this is essentially useless.

A much better alternative would be to use

throwable.stackTraceToString()

which includes all those details formatted into a single string.

For the above error this shows

io.ktor.serialization.JsonConvertException: Illegal input: There was an error during file or class initialization
    at 0   ios_app                             0x108672347        kfun:kotlin.Exception#<init>(kotlin.String?;kotlin.Throwable?){} + 143 
    at 1   ios_app                             0x1085fdddf        kfun:io.ktor.serialization.ContentConvertException#<init>(kotlin.String;kotlin.Throwable?){} + 123 
    at 2   ios_app                             0x1085fdfa3        kfun:io.ktor.serialization.JsonConvertException#<init>(kotlin.String;kotlin.Throwable?){} + 123 
    at 3   ios_app                             0x108601faf        kfun:io.ktor.serialization.kotlinx.KotlinxSerializationConverter.$deserializeCOROUTINE$3.invokeSuspend#internal + 2771 
[...]
Caused by: kotlin.native.internal.FileFailedToInitializeException: There was an error during file or class initialization
    at 0   ios_app                             0x1086721af        kfun:kotlin.Error#<init>(kotlin.String?;kotlin.Throwable?){} + 143 
    at 1   ios_app                             0x1086af627        kfun:kotlin.native.internal.FileFailedToInitializeException#<init>(kotlin.String?;kotlin.Throwable?){} + 143 
[...]
Caused by: kotlin.IllegalArgumentException: The name of serial descriptor should uniquely identify associated serializer.
For serial name kotlin.uuid.Uuid there already exists UuidSerializer.
Please refer to SerialDescriptor documentation for additional information.
    at 0   ios_app                             0x108678e63        kfun:kotlin.Throwable#<init>(kotlin.String?){} + 119 
    at 1   ios_app                             0x1086722a3        kfun:kotlin.Exception#<init>(kotlin.String?){} + 115 
[...]

kodebach avatar Oct 03 '24 18:10 kodebach