Skip to content
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

XcodeSeverityWriter and OSLogWriter should use stackTraceToString #404

Closed
kodebach opened this issue Oct 3, 2024 · 0 comments · Fixed by #417
Closed

XcodeSeverityWriter and OSLogWriter should use stackTraceToString #404

kodebach opened this issue Oct 3, 2024 · 0 comments · Fixed by #417

Comments

@kodebach
Copy link

kodebach commented Oct 3, 2024

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 
[...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant