customerio / customerio-android

This is the official Customer.io SDK for Android.
MIT License
12 stars 9 forks source link

Fatal Exception: com.squareup.moshi.JsonEncodingException: Use JsonReader.setLenient(true) to accept malformed JSON at path $ #123

Closed ivabra closed 2 years ago

ivabra commented 2 years ago

Version(s) of SDK bug appears: 2.0.1 Android versions: 9-12 Kotlin version: 1.7.10

Current Behavior

The app is crashed in first 5 seconds.

Steps to Reproduce

Initialise customer io sdk with this code:

 CustomerIO.Builder(
        siteId = application.getString(R.string.customer_io_site_id),
        apiKey = application.getString(R.string.customer_io_api_key),
        appContext = application,
        region = Region.EU
  ).autoTrackScreenViews(false).build()

Expected Behavior

The app shouldn't be crashed.

Any other info?

Stack trace:

Fatal Exception: com.squareup.moshi.JsonEncodingException: Use JsonReader.setLenient(true) to accept malformed JSON at path $
       at com.squareup.moshi.JsonReader.syntaxError(JsonReader.java:243)
       at com.squareup.moshi.JsonUtf8Reader.checkLenient(JsonUtf8Reader.java:1152)
       at com.squareup.moshi.JsonUtf8Reader.doPeek(JsonUtf8Reader.java:326)
       at com.squareup.moshi.JsonUtf8Reader.peek(JsonUtf8Reader.java:206)
       at com.squareup.moshi.JsonAdapter.fromJson(JsonAdapter.java:71)
       at io.customer.sdk.queue.QueueStorageImpl.getInventory(QueueStorage.kt:172)
       at io.customer.sdk.queue.QueueStorageImpl.deleteExpired(QueueStorage.kt:131)
       at io.customer.sdk.queue.QueueImpl.deleteExpiredTasks(Queue.kt:215)
       at io.customer.sdk.repository.CleanupRepositoryImpl.cleanup(CleanupRepository.kt:17)
       at io.customer.sdk.CustomerIO$postInitialize$1.invokeSuspend(CustomerIO.kt:232)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
       at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
       at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
levibostian commented 2 years ago

Thanks for reporting this to us @ivabra. Let me try to help.

It would be most helpful if you could send us logs from the Customer.io SDK so we can debug this easier.

Follow these steps, please:

  1. Enable SDK debug logging to make the Customer.io SDK print debug logs to logcat. All logs are prefixed with "[CIO]" so you can filter logcat by these logs.
  2. Run your app until the crash occurs. Copy and paste all Customer.io SDK logs from logcat into a text file.
  3. Send us this logs file to win [at] customer.io referencing this GitHub issue in the body of the message.

We will take a look at the logs to see what we think this issue is for.

ivabra commented 2 years ago

@levibostian Thanks, will do, but the thing is that the crash has never occurred during development and we only getting reports from some of our production users. We had to fork the repository and use lenient() to temporary stop crashes for these users.

mrehan27 commented 2 years ago

@ivabra Thanks for the updates. The crash should be fixed in 2.1.1. Please try the latest release and re-open it if the crash still occurs.

SeijiFukuoka commented 1 year ago

I'm using the last version of CustomerIO 2.1.1, however, this crash still happens.

Someone could help me?

Stack trace:

Fatal Exception: com.squareup.moshi.JsonEncodingException: Use JsonReader.setLenient(true) to accept malformed JSON at path $
       at com.squareup.moshi.JsonReader.syntaxError(JsonReader.java:243)
       at com.squareup.moshi.JsonUtf8Reader.checkLenient(JsonUtf8Reader.java:1152)
       at com.squareup.moshi.JsonUtf8Reader.doPeek(JsonUtf8Reader.java:384)
       at com.squareup.moshi.JsonUtf8Reader.peek(JsonUtf8Reader.java:206)
       at com.squareup.moshi.internal.NullSafeJsonAdapter.fromJson(NullSafeJsonAdapter.java:38)
       at com.squareup.moshi.JsonAdapter.fromJson(JsonAdapter.java:70)
       at io.customer.sdk.queue.QueueStorageImpl.get(QueueStorage.kt:208)
       at io.customer.sdk.queue.QueueRunRequestImpl.runTasks(QueueRunRequest.kt:37)
       at io.customer.sdk.queue.QueueRunRequestImpl.goToNextTask(QueueRunRequest.kt:84)
       at io.customer.sdk.queue.QueueRunRequestImpl.runTasks(QueueRunRequest.kt:43)
       at io.customer.sdk.queue.QueueRunRequestImpl.goToNextTask(QueueRunRequest.kt:84)
       at io.customer.sdk.queue.QueueRunRequestImpl.runTasks(QueueRunRequest.kt:43)
       at io.customer.sdk.queue.QueueRunRequestImpl.runTasks$default(QueueRunRequest.kt:26)
       at io.customer.sdk.queue.QueueRunRequestImpl.run(QueueRunRequest.kt:23)
       at io.customer.sdk.queue.QueueImpl.run(Queue.kt:99)
       at io.customer.sdk.queue.QueueImpl$runAsync$1.invokeSuspend(Queue.kt:109)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:571)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
Shahroz16 commented 1 year ago

Hey, @SeijiFukuoka thanks for writing in, that's odd, would it be possible to share more logs? you can enable logs by setting the configuration logLevel to debug .

SeijiFukuoka commented 1 year ago

Unfortunately, I don't have more logs about, it because I can't reproduce this crash. I have only firebase crashlytics log.

I have some information about firebase crashlytics stack log, I don't know if it helps.

Captura de Tela 2022-10-06 às 09 04 04 Captura de Tela 2022-10-06 às 09 04 35

mrehan27 commented 1 year ago

@SeijiFukuoka Thanks for sharing the logs, it will help. This looks like coming from a different path, we'll make this parsing safe too and include in our next release. Meanwhile, please let us know if you face more occurrences of this or if there is any similar crash.

Shahroz16 commented 1 year ago

@SeijiFukuoka 3.1.0-alpha.1 is out with the fix, can you please check and confirm, if possible?

SeijiFukuoka commented 1 year ago

Ok, @Shahroz16. I will put this version on our next release and bring updates soon.