streetcomplete / StreetComplete

Easy to use OpenStreetMap editor for Android
https://streetcomplete.app
GNU General Public License v3.0
3.85k stars 352 forks source link

Crash on startup after upgrade from old version (ALTER TABLE failure?) #5873

Closed mnalis closed 3 weeks ago

mnalis commented 3 weeks ago

Updated from old SC version (exact old SC version unfortunately unknown, but probably about a year to year and a half old - as Vespucci 19.0.3.0 is installed and was probably current at that time), app crashes on startup, and attempted restarts also crash (instead of offering to send logs)

Crash log:

java.lang.RuntimeException: Unable to create application de.westnordost.streetcomplete.StreetCompleteApplication: org.koin.core.error.InstanceCreationException: Could not create instance for '[Singleton:'de.westnordost.streetcomplete.util.logs.DatabaseLogger']'
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4831)
    at android.app.ActivityThread.access$1800(ActivityThread.java:151)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1461)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:157)
    at android.app.ActivityThread.main(ActivityThread.java:5603)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
Caused by: org.koin.core.error.InstanceCreationException: Could not create instance for '[Singleton:'de.westnordost.streetcomplete.util.logs.DatabaseLogger']'
    at org.koin.core.instance.InstanceFactory.create(SourceFile)
    at org.koin.core.instance.SingleInstanceFactory.create(SourceFile)
    at org.koin.core.instance.SingleInstanceFactory$get$1.invoke(SourceFile:0)
    at org.koin.core.instance.SingleInstanceFactory$get$1.invoke(SourceFile:0)
    at org.koin.mp.KoinPlatformTools.synchronized(SourceFile)
    at org.koin.core.instance.SingleInstanceFactory.get(SourceFile)
    at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(SourceFile)
    at org.koin.core.scope.Scope.resolveValue(SourceFile)
    at org.koin.core.scope.Scope.resolveInstance(SourceFile)
    at org.koin.core.scope.Scope.get(SourceFile)
    at de.westnordost.streetcomplete.StreetCompleteApplication$special$$inlined$inject$default$2.invoke(SourceFile)
    at kotlin.SynchronizedLazyImpl.getValue(SourceFile)
    at de.westnordost.streetcomplete.StreetCompleteApplication.getDatabaseLogger(SourceFile)
    at de.westnordost.streetcomplete.StreetCompleteApplication.setLoggerInstances(SourceFile)
    at de.westnordost.streetcomplete.StreetCompleteApplication.onCreate(SourceFile)
    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1014)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4828)
    ... 8 more
Caused by: org.koin.core.error.InstanceCreationException: Could not create instance for '[Singleton:'de.westnordost.streetcomplete.data.logs.LogsController']'
    at org.koin.core.instance.InstanceFactory.create(SourceFile)
    at org.koin.core.instance.SingleInstanceFactory.create(SourceFile)
    at org.koin.core.instance.SingleInstanceFactory$get$1.invoke(SourceFile:0)
    at org.koin.core.instance.SingleInstanceFactory$get$1.invoke(SourceFile:0)
    at org.koin.mp.KoinPlatformTools.synchronized(SourceFile)
    at org.koin.core.instance.SingleInstanceFactory.get(SourceFile)
    at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(SourceFile)
    at org.koin.core.scope.Scope.resolveValue(SourceFile)
    at org.koin.core.scope.Scope.resolveInstance(SourceFile)
    at org.koin.core.scope.Scope.get(SourceFile)
    at de.westnordost.streetcomplete.ApplicationModuleKt.appModule$lambda$8$lambda$3(SourceFile)
    at de.westnordost.streetcomplete.ApplicationModuleKt.$r8$lambda$3-TyuVXRL1xv-ahvDgr6BgsTHHE(SourceFile:0)
    at de.westnordost.streetcomplete.ApplicationModuleKt$$ExternalSyntheticLambda5.invoke(SourceFile:0)
    ... 25 more
Caused by: org.koin.core.error.InstanceCreationException: Could not create instance for '[Factory:'de.westnordost.streetcomplete.data.logs.LogsDao']'
    at org.koin.core.instance.InstanceFactory.create(SourceFile)
    at org.koin.core.instance.FactoryInstanceFactory.get(SourceFile)
    at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(SourceFile)
    at org.koin.core.scope.Scope.resolveValue(SourceFile)
    at org.koin.core.scope.Scope.resolveInstance(SourceFile)
    at org.koin.core.scope.Scope.get(SourceFile)
    at de.westnordost.streetcomplete.data.logs.LogsModuleKt.logsModule$lambda$2$lambda$1(SourceFile)
    at de.westnordost.streetcomplete.data.logs.LogsModuleKt.$r8$lambda$kyS79NN-INclZLCZGB8PYd6ph10(SourceFile:0)
    at de.westnordost.streetcomplete.data.logs.LogsModuleKt$$ExternalSyntheticLambda2.invoke(SourceFile:0)
    ... 38 more
Caused by: org.koin.core.error.InstanceCreationException: Could not create instance for '[Singleton:'de.westnordost.streetcomplete.data.Database']'
    at org.koin.core.instance.InstanceFactory.create(SourceFile)
    at org.koin.core.instance.SingleInstanceFactory.create(SourceFile)
    at org.koin.core.instance.SingleInstanceFactory$get$1.invoke(SourceFile:0)
    at org.koin.core.instance.SingleInstanceFactory$get$1.invoke(SourceFile:0)
    at org.koin.mp.KoinPlatformTools.synchronized(SourceFile)
    at org.koin.core.instance.SingleInstanceFactory.get(SourceFile)
    at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(SourceFile)
    at org.koin.core.scope.Scope.resolveValue(SourceFile)
    at org.koin.core.scope.Scope.resolveInstance(SourceFile)
    at org.koin.core.scope.Scope.get(SourceFile)
    at de.westnordost.streetcomplete.data.logs.LogsModuleKt.logsModule$lambda$2$lambda$0(SourceFile)
    at de.westnordost.streetcomplete.data.logs.LogsModuleKt.$r8$lambda$i-oS8Q7Mi4HXv9zHfsTHA1uUv00(SourceFile:0)
    at de.westnordost.streetcomplete.data.logs.LogsModuleKt$$ExternalSyntheticLambda1.invoke(SourceFile:0)
    ... 47 more
Caused by: android.database.sqlite.SQLiteException: duplicate column name: is_near (code 1): , while compiling: ALTER TABLE osm_element_edits ADD COLUMN is_near int DEFAULT 1 NOT NULL
    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
    at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
    at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1674)
    at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605)
    at de.westnordost.streetcomplete.data.AndroidDatabase.exec(SourceFile)
    at de.westnordost.streetcomplete.data.Database$DefaultImpls.exec$default(SourceFile)
    at de.westnordost.streetcomplete.data.DatabaseInitializer.onUpgrade(SourceFile)
    at de.westnordost.streetcomplete.data.StreetCompleteSQLiteOpenHelper.onUpgrade(SourceFile)
    at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:256)
    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
    at de.westnordost.streetcomplete.data.DbModuleKt.dbModule$lambda$1$lambda$0(SourceFile)
    at de.westnordost.streetcomplete.data.DbModuleKt.$r8$lambda$IGJU7etnWCTnBhldDo5YiS03WyI(SourceFile:0)
    at de.westnordost.streetcomplete.data.DbModuleKt$$ExternalSyntheticLambda1.invoke(SourceFile:0)
    ... 60 more

How to Reproduce

Expected Behavior I'd expeect SC to start up normally.

Also, if crashing, it would be nice if offering to send crash log on app startup was done very early; i.e. before database updates, map initialization and other things that are somewhat likely to crash again.

Versions affected StreetComplete 59.0-alpha4 on Android 6.0.1 (Xiaomi Redmi Note 3)

westnordost commented 3 weeks ago

It looks like the fault is here:

https://github.com/streetcomplete/StreetComplete/blob/4a460fe4fd6bbbca1387ef9db0394a4da860edef/app/src/main/java/de/westnordost/streetcomplete/data/DatabaseInitializer.kt#L234

The column already exists in your database. The column is part of a feature implemented in #5474, released in v57.0.

It would be very helpful if we knew from which version you tried to upgrade so that it can be reproduced. There must be something special about upgrading from that version, because otherwise this error would have happened for others upgrading to v57.0, too.

mnalis commented 3 weeks ago

As it was signed by GitHub key (given that upgrade worked), it would indicate I downloaded previous version from GitHub too, which in turn indicates I was doing testing on some previous version (otherwise I'd be installing from F-droid)...

Rummaging through the logcat, I've found this about the time of upgrade/crash:

09-04 22:43:29.399 13717 13717 I Finsky  : [1] aryp.h(131): UCtl: Capture account null for next update of de.westnordost.streetcomplete
09-04 22:43:32.322 13717 14013 I Finsky  : [883] ahir.run(436): UCtl: For package de.westnordost.streetcomplete, first update discovery timestamp is set to 2022-07-16T12:27:28.051854Z
09-04 22:43:32.375 13717 14013 I Finsky  : [883] ahir.run(640): UCtl: Package de.westnordost.streetcomplete client staleness timestamp changed from 2022-07-16T12:27:31.408Z to 2022-07-16T12:27:31.408Z, available version changed from 5501 to 5803 or in-app update priority changed from 0 to 0, Server update discovery timestamp is changed from 2022-07-16T12:27:28.051854Z to 2022-07-16T12:27:28.051854Z
09-04 22:43:32.977 15473 15473 I StreetCompleteApplication: onTrimMemory, level 60: 445 MB of 1850 available, mem low: false, mem low threshold: 216 MB
09-04 22:43:36.117  7141  7224 D PowerKeeper.Event: notifyAMProcDied pacakageName: de.westnordost.streetcomplete, pid:15312
09-04 22:43:37.450 13717 13717 I Finsky  : [1] aryp.h(131): UCtl: Capture account null for next update of de.westnordost.streetcomplete

That available version changed from 5501 to 5803 seems like it might be a clue? (And that first update discovery timestamp is set to 2022-07-16T12:27:28.051854Z might indicate that 5501 was in itself an upgrade from some previous version?)

westnordost commented 3 weeks ago

Could you try if it is reproducible when you download and install 5501, then upgrade to current?

mnalis commented 3 weeks ago

That 5501 turned out to be red herring, but going by the versions/dates of other apps, I've found that after uninstalling, and then freshly installing SC 52.0, starting it up, and upgrading to v59.0-alpha4 leads to that crash.

westnordost commented 3 weeks ago

Thank you for your investigation!