amplitude / Amplitude-Kotlin

Amplitude Kotlin SDK
MIT License
27 stars 10 forks source link

DataMigration NotImplementedError #146

Closed brianwernick closed 11 months ago

brianwernick commented 1 year ago

Expected Behavior

When Amplitude is initialized the RemnantDataMigration is skipped when the DB doesn't exist (i.e. no error is thrown)

Current Behavior

When Amplitude is initialized the RemnantDataMigration throws the following exception

Fatal Exception: kotlin.NotImplementedError: An operation is not implemented.
       at kotlin.NotImplementedError.<init>(NotImplementedError.java:15)
       at com.amplitude.android.migration.DatabaseStorage.onCreate(DatabaseStorage.kt:53)
       at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:486)
       at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:415)
       at com.amplitude.android.migration.DatabaseStorage.getValueFromTable(DatabaseStorage.kt:222)
       at com.amplitude.android.migration.DatabaseStorage.getValue(DatabaseStorage.kt:206)
       at com.amplitude.android.migration.RemnantDataMigration.moveDeviceAndUserId(RemnantDataMigration.kt:48)
       at com.amplitude.android.migration.RemnantDataMigration.execute(RemnantDataMigration.kt:36)
       at com.amplitude.android.Amplitude.buildInternal$suspendImpl(Amplitude.kt:55)
       at com.amplitude.android.Amplitude.buildInternal(Amplitude.kt:1)
       at com.amplitude.core.Amplitude$build$built$1.invokeSuspend(Amplitude.kt:107)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run(Thread.java:919)

Possible Solution

Before attempting to migrate any data the RemnantDataMigration should first check if the Database exists and skip the migration if it doesn't (since the DatabaseStorage intentionally doesn't support creation).

Steps to Reproduce

Unfortunately this is being reported through Crashlytics on user devices so I don't have a set of reproduction steps, if you need more information please let me know and I'll try to provide it.

Environment

justin-fiedler commented 1 year ago

Hi @brianwernick thanks for filing this issue. We will investigate and work on a fix.

justin-fiedler commented 11 months ago

Fix released in 1.11.1. Thanks @brianwernick!