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

JsonDecodingException in VersionedCodec #80

Open
shlauzer opened this issue Dec 13, 2023 · 4 comments
Open

JsonDecodingException in VersionedCodec #80

shlauzer opened this issue Dec 13, 2023 · 4 comments

Comments

@shlauzer
Copy link

shlauzer commented Dec 13, 2023

We've got the non-fatal error in Crashlytics with the following stacktrace:

Non-fatal Exception: kotlinx.serialization.json.internal.JsonDecodingException Unexpected JSON token at offset 0: Expected numeric literal at path: $ JSON input: kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException (JsonExceptions.kt:24) kotlinx.serialization.json.okio.OkioStreamsKt.decodeFromBufferedSource (OkioStreams.kt:65) io.github.xxfast.kstore.file.extensions.VersionedCodec.decode (KVersionedStore.kt:68) io.github.xxfast.kstore.KStore$read$2.invokeSuspend (KStore.kt:40) ...

We use KStore 0.6.0 in the similar way:

val kstore = storeOf(
    filePath = "$storePath/application_$applicationId.json",
    version = 0,
    enableCache = true,
    json = json
)

kstore.update {
   ...
}

where storePath is application.applicationContext.filesDir.path + "/cross_sell"

It looks like a problem in version file reading: https://github.com/xxfast/KStore/blob/0.6.0/kstore-file/src/commonMain/kotlin/io/github/xxfast/kstore/file/extensions/KVersionedStore.kt#L67C33-L68C1. Have you any ideas?

Also I see that you are going to save version to file metadata instead. Do you have any plans?

@xxfast
Copy link
Owner

xxfast commented Dec 19, 2023

Hi @shlauzer. Is there a reason you are using the KVersionedStore without a migration plan? If you don't wish to version, you can use the regular factory method documented here

As for the crash - it looks like the JSON file is malformed. I assume this was because the coroutine context was cancelled amid a write operation. This could be fixed in #77 but further investigation is needed.

@shlauzer
Copy link
Author

Hi @xxfast. Actually we don't need versioning in this moment and we can use storeOf with FileCodec. But I have a question about it. If we still change our class(e.g. add some new fields), will KStore return default value or throw exception?

@xxfast
Copy link
Owner

xxfast commented Jan 11, 2024

@shlauzer depends.

Refer to this doc for binary compatible migrations https://xxfast.github.io/KStore/using-versioning.html#binary-incompatible-changes

@shlauzer
Copy link
Author

shlauzer commented Jan 11, 2024

@xxfast As far as I understand we still need VersiondedCodec. If we decide to change our model we will be able to catch our jsonElement with version = 0 and migrate it manually.

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

No branches or pull requests

2 participants