Kermit icon indicating copy to clipboard operation
Kermit copied to clipboard

Crash on iOS devices < iOS 13

Open tylerwilson opened this issue 3 years ago • 3 comments

I happen to be testing my iOS/KMM app on an iOS 12.5.5 device, and there was a crash related to the Kermit code. Here is the call stack:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSDate now]: unrecognized selector sent to class 0x10bc82898' *** First throw call stack: ( 0 CoreFoundation 0x000000010b9d58db __exceptionPreprocess + 331 1 libobjc.A.dylib 0x000000010af80ac5 objc_exception_throw + 48 2 CoreFoundation 0x000000010b9f3b94 +[NSObject(NSObject) doesNotRecognizeSelector:] + 132 3 CoreFoundation 0x000000010b9da623 ___forwarding___ + 1443 4 CoreFoundation 0x000000010b9dc418 _CF_forwarding_prep_0 + 120 5 SalonBiz 0x0000000108ff6908 kfun:co.touchlab.kermit.XcodeSeverityWriter#formatMessage(co.touchlab.kermit.Severity;kotlin.String;kotlin.String;kotlin.Throwable?){}kotlin.String + 808 6 SalonBiz 0x0000000108ff37e7 kfun:co.touchlab.kermit.CommonWriter#log(co.touchlab.kermit.Severity;kotlin.String;kotlin.String;kotlin.Throwable?){} + 375 7 SalonBiz 0x0000000108ff51d6 kfun:co.touchlab.kermit.Logger#log(co.touchlab.kermit.Severity;kotlin.String;kotlin.Throwable?;kotlin.String){} + 950 8 SalonBiz 0x0000000108ff4dc9 kfun:co.touchlab.kermit.Logger#d(kotlin.String){} + 777

We see here that NSDate.now is being called, which is an iOS 13+ API. What is odd is that I searched the kermit repo, and there are no explicit calls to this method. So perhaps it is something in the compiler or stdlib?

I removed kermit from my code for now, but thought I should let others know what I found. Thank you!

tylerwilson avatar Jan 25 '22 14:01 tylerwilson

We called it in an older version of XcodeSeverityWriter

https://github.com/touchlab/Kermit/commit/a2ac8542049d89dd5dbbb656a86ee3a00ace0e3f#diff-bb104ec6ef40cec0884cb7375c884cc2574852b19dbdf201793ec96f8c8d73b1R21

That class has been updated with the os_log calls that already provide a timestamp. I don't know if those have an iOS version floor (docs say 10+ https://developer.apple.com/documentation/os/os_log).

You can (and probably should) have a different config for production. I have a post about this that's not published yet, but you can see the production sample. In production, we only set up crashlytics: https://github.com/touchlab/Kermit/blob/main/samples/sample-production/shared/src/commonMain/kotlin/co/touchlab/kermitsample/Helpers.kt#L19

Alternatively, just use CommonWriter which only does println().

kpgalligan avatar Jan 25 '22 15:01 kpgalligan

To be clear, we haven't released a version with that yet. I had some other API changes that I wanted to take a second look at before pushing, but we should probably just release.

kpgalligan avatar Jan 25 '22 15:01 kpgalligan

No wonder I could not find it - was checking main branch of course. Looks like a good fix. Will wait for the next release and update here when I verify. Thanks!

tylerwilson avatar Jan 25 '22 17:01 tylerwilson

Sorry for the late update, this fix was released in version 1.1.0, thanks for the report!

mrf7 avatar Oct 25 '22 17:10 mrf7