Skip to content

Commit 39c81d5

Browse files
david-allisonmikehardy
authored andcommitted
fix: silent crash on startup due to fatal error
A fatal error was a `RuntimeException`, as `Error` only catches `Error` and not `Exception`, this was not caught Now, a 'collection not opened' dialog appears This also fixes the same issue in `DebugInfoService` Fixes 16963
1 parent 1c9fa96 commit 39c81d5

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/DebugInfoService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ object DebugInfoService {
8282

8383
private suspend fun getFSRSStatus(): Boolean? = try {
8484
CollectionManager.withOpenColOrNull { config.get<Boolean>("fsrs", false) }
85-
} catch (e: Error) {
85+
} catch (e: Throwable) { // Error and Exception paths are the same, so catch Throwable
8686
Timber.w(e)
8787
null
8888
}

AnkiDroid/src/main/java/com/ichi2/anki/services/BootService.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ class BootService : BroadcastReceiver() {
6969
// getInstance().getColSafe
7070
return try {
7171
CollectionManager.getColUnsafe()
72-
} catch (e: Error) { // java.lang.UnsatisfiedLinkError occurs in tests
72+
} catch (e: Throwable) { // Error and Exception paths are the same, so catch Throwable
73+
// BackendException.BackendFatalError is a RuntimeException
74+
// java.lang.UnsatisfiedLinkError occurs in tests
7375
Timber.e(e, "Failed to get collection for boot service - possibly media ejecting")
7476
null
7577
}

AnkiDroid/src/test/java/com/ichi2/anki/AnkiDroidAppFailureTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ import com.ichi2.testutils.AnkiDroidAppWithFatalError
2121
import org.junit.Test
2222
import org.junit.runner.RunWith
2323
import org.robolectric.annotation.Config
24-
import kotlin.test.Ignore
2524

2625
@RunWith(AndroidJUnit4::class)
2726
@Config(application = AnkiDroidAppWithFatalError::class)
2827
class AnkiDroidAppFailureTest : RobolectricTest() {
2928
@Test
30-
@Ignore("#16963")
3129
fun `fatal error does not crash onCreate`() {
3230
}
3331
}

0 commit comments

Comments
 (0)