Deck action preparation hides database corruption
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 56/100
Research direction
Start with the regression test shown in the issue, DeckPickerPreparedActionCorruptionRegressionTest.kt, which covers deletion confirmation and the Study shortcut when reading the selected deck fails. Trace how those actions prepare a deck and handle backend corruption, then compare that path with the existing database recovery handling. Done means both cases detect corruption and open DatabaseErrorDialog instead of showing a generic error.
Written by the indexing model from the issue text.
Description
[EXISTING] Deck action preparation hides database corruption
Subject: [EXISTING] Deck action preparation hides database corruption
Backend corruption while preparing Delete or the Study shortcut becomes a generic error, hiding database recovery.
⚠️ This issue existed before the PR and should likely be split off into a separate issue.
---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/DeckPickerPreparedActionCorruptionRegressionTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/DeckPickerPreparedActionCorruptionRegressionTest.kt
new file mode 100644
index 0000000000000000000000000000000000000000..3c2c4ac14d7d40656f0469e5241b26b2241b5175
--- /dev/null
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/DeckPickerPreparedActionCorruptionRegressionTest.kt
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package com.ichi2.anki
+
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import anki.backend.backendError
+import com.ichi2.anki.backend.DatabaseCorruption
+import com.ichi2.anki.deckpicker.DeckPickerViewModel
+import com.ichi2.anki.dialogs.DatabaseErrorDialog
+import com.ichi2.testutils.rules.BackendOverrideRule
+import kotlinx.coroutines.Job
+import net.ankiweb.rsdroid.Backend
+import net.ankiweb.rsdroid.BackendException.BackendDbException.BackendDbCorruptException
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.shadows.ShadowDialog
+import java.util.concurrent.atomic.AtomicBoolean
+import kotlin.test.assertTrue
+
+@RunWith(AndroidJUnit4::class)
+class DeckPickerPreparedActionCorruptionRegressionTest : RobolectricTest() {
+ @get:Rule
+ val backendOverride = BackendOverrideRule()
+
+ @Test
+ fun `corruption reading the deck for deletion confirmation opens recovery`() = checkCorruption { requestDeleteDeckConfirmation() }
+
+ @Test
+ fun `corruption reading the deck for the study shortcut opens recovery`() = checkCorruption { requestStudySelectedDeck() }
+
+ private fun checkCorruption(request: DeckPickerViewModel.() -> Job) {
+ val failNextRead = AtomicBoolean(false)
+ backendOverride.replaceWith {
+ object : Backend() {
+ override fun getCurrentDeck(): anki.decks.Deck =
+ if (failNextRead.getAndSet(false)) {
+ throw BackendDbCorruptException(backendError { message = "database disk image is malformed" })
+ } else {
+ super.getCurrentDeck()
+ }
+ }
+ }
+ addDeck("Target", setAsSelected = true)
+ val previouslyDetected = DatabaseCorruption.isDetected
+ DatabaseCorruption.isDetected = false
+ try {
+ withDeckPicker(deckCount = 0) { picker ->
+ advanceRobolectricLooperUntil { picker.viewModel.loadDeckCounts?.isCompleted == true }
+ advanceRobolectricLooper()
+ throwOnShowError = false
+ failNextRead.set(true)
+ val action = picker.viewModel.request()
+ advanceRobolectricLooperUntil { action.isCompleted && ShadowDialog.getLatestDialog()?.isShowing == true }
+ assertTrue(DatabaseCorruption.isDetected, "Preparing a deck action must preserve corruption detection")
+ assertTrue(
+ picker.supportFragmentManager.fragments.any { it is DatabaseErrorDialog && it.dialog?.isShowing == true },
+ "Preparing a deck action must open recovery instead of a generic error alert",
+ )
+ }
+ } finally {
+ DatabaseCorruption.isDetected = previouslyDetected
+ }
+ }
+}
Originally posted by @david-allison in https://github.com/ankidroid/Anki-Android/pull/22504#pullrequestreview-5860114910
- Dominant language
- Kotlin
- Stars
- 12.3k
- Forks
- 3.1k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 383
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ankidroid/Anki-Android
-
Needs Triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ankidroid/Anki-Android#23392 ·
Maintainers usually reply within 1 day
-
Needs Triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ankidroid/Anki-Android#23390 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
ankidroid/Anki-Android#23385 · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
ankidroid/Anki-Android#23374 ·
Maintainers usually reply within 1 day
-
Selected custom-study tags become unreadablePossibly taken @chesh-ire claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
ankidroid/Anki-Android#23352 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
All issues in ankidroid/Anki-Android
Similar issues
-
Bug Domain changed
Difficulty 1/5 Under an hour Newbie friendliness 79/100
keiyoushi/extensions-source#21174 ·
Maintainers usually reply within 1 day
-
Unified account interface not translated into Simplified ChinesePossibly taken @xuenhua claimed this 3 days ago. Openunconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
thunderbird/thunderbird-android#11936 · 1 comment ·
Maintainers usually reply within 3 days
-
Update toast stylingOpendesign good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
scribe-org/Scribe-Android#778 ·
Maintainers usually reply within 1 day
-
AI Generated CI/CD ⚒️ Flaky-tests 🐦 go 🏃
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
valkey-io/valkey-glide#7772 ·
Maintainers usually reply within 1 day
-
Error Handling Swift
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Automattic/wordpress-rs#1759 ·
Maintainers usually reply within 1 day