ankidroid / Anki-Android

AnkiDroid: Anki flashcards on Android. Your secret trick to achieve superhuman information retention.
GNU General Public License v3.0
8.75k stars 2.24k forks source link

Expose exceptions thrown during caching of imported files #17429

Closed lukstbit closed 1 week ago

lukstbit commented 1 week ago

Purpose / Description

We have a lot of reports in the form of:

java.lang.RuntimeException: Error importing apkg file
    at com.ichi2.utils.ImportUtils$FileImporter.handleContentProviderFile(ImportUtils.java:211)
    at com.ichi2.utils.ImportUtils$FileImporter.handleFileImportInternal(ImportUtils.java:128)
    at com.ichi2.utils.ImportUtils$FileImporter.handleFileImport(ImportUtils.java:117)
    at com.ichi2.utils.ImportUtils.handleFileImport(ImportUtils.java:61)

coming from:

https://github.com/ankidroid/Anki-Android/blob/f4b08261418fca31293629a55d341b861c0fbb73/AnkiDroid/src/main/java/com/ichi2/utils/ImportUtils.kt#L203-L211

which are a front for problems in the ImportUtils.copyToCache() method:

https://github.com/ankidroid/Anki-Android/blob/f4b08261418fca31293629a55d341b861c0fbb73/AnkiDroid/src/main/java/com/ichi2/utils/ImportUtils.kt#L306-L327

This PR "extracts" any exception happening in that method and sends it to acra instead of the current useless RuntimeException we are sending. Having the real exceptions could helps us to see what's really happening.

Checklist

lukstbit commented 1 week ago

It does expose the filenames. I removed the exceptions instances and instead added some messages about what is happening as additional info to the report.

mikehardy commented 6 days ago

Huh. Took one of these on 2.19.2 and it looks like:


11-19 17:26:41.861 E/AnkiDroid(18162): java.io.FileNotFoundException: open failed: ENOENT (No such file or directory)
11-19 17:26:41.861 E/AnkiDroid(18162):  at android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:351)
11-19 17:26:41.861 E/AnkiDroid(18162):  at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:230)
11-19 17:26:41.861 E/AnkiDroid(18162):  at androidx.core.content.FileProvider.openFile(SourceFile:84)
11-19 17:26:41.861 E/AnkiDroid(18162):  at android.content.ContentProvider.openAssetFile(ContentProvider.java:2310)
11-19 17:26:41.861 E/AnkiDroid(18162):  at android.content.ContentProvider.openTypedAssetFile(ContentProvider.java:2488)
11-19 17:26:41.861 E/AnkiDroid(18162):  at android.content.ContentProvider.openTypedAssetFile(ContentProvider.java:2555)
11-19 17:26:41.861 E/AnkiDroid(18162):  at android.content.ContentProvider$Transport.openTypedAssetFile(ContentProvider.java:672)
11-19 17:26:41.861 E/AnkiDroid(18162):  at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:2043)
11-19 17:26:41.861 E/AnkiDroid(18162):  at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1858)
11-19 17:26:41.861 E/AnkiDroid(18162):  at android.content.ContentResolver.openInputStream(ContentResolver.java:1528)

FileNotFoundException 🤔