Skip to content

fix(media-check): show errors instead of crashing - #22171

Open
criticalAY wants to merge 1 commit into
ankidroid:mainfrom
criticalAY:fix/media-check-error-handling
Open

criticalAY wants to merge 1 commit into
ankidroid:mainfrom
criticalAY:fix/media-check-error-handling

Conversation

@criticalAY

Copy link
Copy Markdown
Contributor

Note

Assisted-by: Opus 5.5 (Analysis of root cause)

Purpose / Description

Opening Check Media crashes the app if the backend throws. On GrapheneOS with Storage Scopes, listing an empty folder (usually media.trash) fails with Operation not permitted (os error 1), so every check crashes.

All five MediaCheckViewModel ops were a bare viewModelScope.launch, so a failure went straight to the uncaught exception handler. The fragment's launchCatchingTask { op().join() } couldn't catch it, because join() returns normally when the job fails. The check on open wasn't wrapped at all. This has been broken since 2.21alpha14.

Fixes

Approach

The ViewModel ran its operations with viewModelScope.launch, so a failure went straight to the uncaught exception handler. Wrapping them in launchCatchingTask did not help: join() returns normally when the job fails, and the check on open was not wrapped at all.

So the operations now return a Deferred which the fragment awaits, so failures reach launchCatchingTask and show the usual error dialog. sThe result dialogs are no longer shown after a failure.

How Has This Been Tested?

  • New MediaCheckFragmentTest

Learning (optional, can help others)

NA

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@david-allison david-allison left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Can you add a TODO to move this error handling into the ViewModel?

Or if you have the capacity, do it here

@lukstbit lukstbit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@lukstbit lukstbit added Needs Author Reply Waiting for a reply from the original author Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Review labels Sep 29, 2026
Opening Check Media crashed when the backend failed. On GrapheneOS
with Storage Scopes, listing an empty media folder returns
'Operation not permitted (os error 1)', so every check crashed.

Assisted-by: Opus 5.5 (Analysis of root cause)
@criticalAY
criticalAY force-pushed the fix/media-check-error-handling branch from ad9c955 to 4f22f88 Compare September 29, 2026 20:23
@criticalAY

Copy link
Copy Markdown
Contributor Author

Added a TODO for now

@criticalAY criticalAY removed the Needs Author Reply Waiting for a reply from the original author label Sep 29, 2026
@criticalAY
criticalAY added this pull request to the merge queue Sep 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 29, 2026
@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Sep 29, 2026
@david-allison

Copy link
Copy Markdown
Member
e: file:///home/runner/work/Anki-Android/Anki-Android/AnkiDroid/src/test/java/com/ichi2/anki/mediacheck/MediaCheckFragmentTest.kt:72:36 Argument type mismatch: actual type is 'Int', but 'Boolean' was expected.
> Task :AnkiDroid:compilePlayDebugUnitTestKotlin FAILED
e: file:///home/runner/work/Anki-Android/Anki-Android/AnkiDroid/src/test/java/com/ichi2/anki/mediacheck/MediaCheckFragmentTest.kt:72:69 Argument already passed for this parameter.
e: file:///home/runner/work/Anki-Android/Anki-Android/AnkiDroid/src/test/java/com/ichi2/anki/mediacheck/MediaCheckFragmentTest.kt:72:69 No value passed for parameter 'button'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Author Reply Waiting for a reply from the original author Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[checkMedia] BackendIoException: Operation not permitted (os error 1)

3 participants