Deck deletion offers no recovery for unreadable note text

Open
#23,771 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
Half a day
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
android, kotlin
Domain
database, mobile

Research direction

Start with the proposed test DeckPickerDeletionUtf8ErrorTest.kt, which forces removeDecks to throw a Utf8 DB_ERROR and expects deletion to show a DatabaseErrorDialog or a Check Database neutral button. Find where the deck picker handles that backend error and shows the generic alert, then route the repairable case to the existing database recovery dialog. Done when the test passes and the existing deletion tests still pass.

Written by the indexing model from the issue text.

Description

code-scan Needs Triage

Assisted-by: GPT-6.2-Sol xhigh & GPT-6.1-Sol xhigh

Deck deletion offers no recovery for unreadable note text [P2]
Subject: Deck deletion offers no recovery for unreadable note text

A repairable note decoding error blocks deletion and displays a generic alert, leaving the user without a Check Database action.

---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/DeckPickerDeletionUtf8ErrorTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/DeckPickerDeletionUtf8ErrorTest.kt
new file mode 100644
index 0000000000..9fdfa649fd
--- /dev/null
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/DeckPickerDeletionUtf8ErrorTest.kt
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package com.ichi2.anki
+
+import androidx.appcompat.app.AlertDialog
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import anki.backend.BackendError
+import anki.backend.backendError
+import anki.collection.OpChangesWithCount
+import com.ichi2.anki.CollectionManager.TR
+import com.ichi2.anki.dialogs.DatabaseErrorDialog
+import com.ichi2.anki.ui.internationalization.sentenceCase
+import com.ichi2.testutils.rules.BackendOverrideRule
+import com.ichi2.utils.neutralButton
+import net.ankiweb.rsdroid.Backend
+import net.ankiweb.rsdroid.BackendException
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.shadows.ShadowDialog
+import kotlin.test.assertNotNull
+import kotlin.test.assertTrue
+
+@RunWith(AndroidJUnit4::class)
+class DeckPickerDeletionUtf8ErrorTest : RobolectricTest() {
+    @get:Rule
+    val backendOverride = BackendOverrideRule()
+
+    @Test
+    fun `deletion blocked by invalid note text offers database recovery`() {
+        val failure =
+            BackendException.fromError(
+                backendError {
+                    kind = BackendError.Kind.DB_ERROR
+                    message = """DbError { info: "", kind: Utf8 }"""
+                },
+            )
+        backendOverride.replaceWith {
+            object : Backend() {
+                override fun removeDecks(dids: Iterable<Long>): OpChangesWithCount = throw failure
+            }
+        }
+        val deckId = addDeck("Deck")
+        addNoteToDeck(deckId)
+
+        withDeckPicker(deckCount = 0) { picker ->
+            picker.awaitVisibleDecks(listOf(deckId))
+            throwOnShowError = false
+            val deletion = picker.deleteDeck(deckId)
+            advanceRobolectricLooperUntil {
+                deletion.isCompleted && (ShadowDialog.getLatestDialog() as? AlertDialog)?.isShowing == true
+            }
+
+            assertNotNull(col.decks.getLegacy(deckId))
+            val alert = ShadowDialog.getLatestDialog() as AlertDialog
+            assertTrue(
+                picker.supportFragmentManager.fragments.any { it is DatabaseErrorDialog } ||
+                    alert.neutralButton?.text == with(picker) { TR.sentenceCase.checkDatabase },
+                "A repairable note decoding error must offer database recovery",
+            )
+        }
+    }
+}

Originally posted by @david-allison in https://github.com/ankidroid/Anki-Android/pull/23699#pullrequestreview-6062894437

Dominant language
Kotlin
Stars
12.3k
Forks
3.1k
Avg merge
2d 1h
Merged PRs (30d)
311

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ankidroid/Anki-Android

All issues in ankidroid/Anki-Android

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.