Skip to content
This repository was archived by the owner on May 6, 2026. It is now read-only.

fix: skip missing media files instead of crashing - #113

Merged
aalemayhu merged 1 commit into
mainfrom
fix/skip-missing-media-files
Apr 12, 2026
Merged

aalemayhu merged 1 commit into
mainfrom
fix/skip-missing-media-files

Conversation

@aalemayhu

Copy link
Copy Markdown
Contributor

Filter out non-existent media files before passing to genanki, so users still get their flashcards even if images are missing from the upload.

Filter out non-existent media files before passing to genanki, so users still get their flashcards even if images are missing from the upload.
@aalemayhu
aalemayhu requested a review from Copilot April 12, 2026 15:11
@coderabbitai

coderabbitai Bot commented Apr 12, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@aalemayhu has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 13 minutes and 7 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 13 minutes and 7 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7b7039e4-145d-472d-95c2-2d7786a9ff94

📥 Commits

Reviewing files that changed from the base of the PR and between b94ee9b and 21834b1.

📒 Files selected for processing (2)
  • helpers/write_apkg.py
  • tests/test_write_apkg.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/skip-missing-media-files

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

Copy link
Copy Markdown

@aalemayhu
aalemayhu merged commit a4ad6ea into main Apr 12, 2026
13 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR prevents APKG generation from failing when some referenced media files are missing by filtering out non-existent media paths before passing them to genanki.Package.

Changes:

  • Filter media_files to only include paths that exist, and emit a stderr warning for skipped entries.
  • Update the existing media test to create real temp files and pass absolute paths.
  • Add a new test to verify missing media paths are skipped.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
helpers/write_apkg.py Filters missing media files before assigning package.media_files and warns on stderr.
tests/test_write_apkg.py Makes media tests use real temp files/paths and adds coverage for missing media behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread helpers/write_apkg.py
Comment on lines +150 to +151
if len(existing_media) < len(media_files):
missing = set(media_files) - set(existing_media)

Copilot AI Apr 12, 2026

Copy link

Choose a reason for hiding this comment

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

missing is computed via set(media_files) - set(existing_media), which collapses duplicates and produces a non-deterministic ordering. Since media_files can contain duplicates (e.g., same image referenced by multiple cards), the reported count/list can be inaccurate and confusing. Consider computing missing as an ordered list (e.g., [f for f in media_files if not os.path.exists(f)]) and using that for both the count and the message.

Suggested change
if len(existing_media) < len(media_files):
missing = set(media_files) - set(existing_media)
missing = [f for f in media_files if not os.path.exists(f)]
if missing:

Copilot uses AI. Check for mistakes.
Comment thread tests/test_write_apkg.py
Comment on lines +131 to +132
open(existing_path, 'w').close()
media_files = [existing_path, 'image.png']

Copilot AI Apr 12, 2026

Copy link

Choose a reason for hiding this comment

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

This test uses a relative path ('image.png') to represent a missing media file. If a file with that name exists in the process working directory (e.g., developer machine/CI workspace), the test can become flaky. Use an absolute path inside tmpdir (e.g., os.path.join(tmpdir, 'image.png')) without creating it to guarantee it is missing.

Suggested change
open(existing_path, 'w').close()
media_files = [existing_path, 'image.png']
missing_path = os.path.join(tmpdir, 'image.png')
open(existing_path, 'w').close()
media_files = [existing_path, missing_path]

Copilot uses AI. Check for mistakes.
@aalemayhu
aalemayhu deleted the fix/skip-missing-media-files branch April 12, 2026 15:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants