Deck deletion offers no recovery for unreadable note text

Aperta
#23,771 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
android, kotlin
Ambito
database, mobile

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Kotlin
Stelle
12.3k
Fork
3.1k
Merge medio
2g 1h
PR unite (30g)
311

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ankidroid/Anki-Android

Tutte le issue di ankidroid/Anki-Android

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.