Skip to content

fetchart: catch OSError in _set_art for graceful permission error handling#6662

Open
terminalchai wants to merge 2 commits into
beetbox:masterfrom
terminalchai:fix/fetchart-permission-error-graceful
Open

fetchart: catch OSError in _set_art for graceful permission error handling#6662
terminalchai wants to merge 2 commits into
beetbox:masterfrom
terminalchai:fix/fetchart-permission-error-graceful

Conversation

@terminalchai
Copy link
Copy Markdown

@terminalchai terminalchai commented May 21, 2026

Problem

When fetchart moves album art to the destination folder, a PermissionError
(or other OSError) can crash beets with an unhandled traceback. This happens
when a file is locked by another process, such as foobar2000 scanning the folder
during import.

Example traceback from #6193:

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process

Fix

Wrap album.set_art() in a try/except OSError block inside _set_art.
On failure, log a warning and return False instead of crashing. The
batch_fetch_art CLI path now checks the return value and reports
"error writing album art" instead of a traceback.

Changes

  • beetsplug/fetchart.py: _set_art now returns bool; catches OSError with a warning log
  • test/plugins/test_fetchart.py: new test test_set_art_oserror_is_handled_gracefully verifies graceful handling when Album.set_art raises PermissionError
  • docs/changelog.rst: bug fix entry added

Fixes #6193

@terminalchai terminalchai requested a review from a team as a code owner May 21, 2026 19:37
@github-actions github-actions Bot added the fetchart fetchart plugin label May 21, 2026
@github-actions
Copy link
Copy Markdown

Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry.

@terminalchai
Copy link
Copy Markdown
Author

Added a regression test ( est_set_art_oserror_is_handled_gracefully) and a changelog entry per the contribution guide. Please re-review when you get a chance!

@terminalchai
Copy link
Copy Markdown
Author

Added a regression test (test_set_art_oserror_is_handled_gracefully) and a changelog entry per the contribution guide. Please re-review when you get a chance!

Copy link
Copy Markdown
Member

@snejus snejus left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@snejus
Copy link
Copy Markdown
Member

snejus commented May 21, 2026

Just resolve the conflict in the changelog please.

@snejus snejus enabled auto-merge May 21, 2026 19:53
…dling

When album art is being moved to the destination folder, a PermissionError (or
other OSError) can occur if the file is locked by another process (e.g. a media
player scanning the folder). Previously this caused an unhandled traceback crash.

Wrap album.set_art() in a try/except OSError block in _set_art, log a warning,
and return False so callers can handle the failure gracefully.

Fixes beetbox#6193
auto-merge was automatically disabled May 22, 2026 20:10

Head branch was pushed to by a user without write access

@terminalchai terminalchai force-pushed the fix/fetchart-permission-error-graceful branch from cc89caf to d686087 Compare May 22, 2026 20:10
@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.47%. Comparing base (da16db1) to head (d686087).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6662   +/-   ##
=======================================
  Coverage   72.46%   72.47%           
=======================================
  Files         161      161           
  Lines       20719    20725    +6     
  Branches     3280     3281    +1     
=======================================
+ Hits        15014    15020    +6     
  Misses       4979     4979           
  Partials      726      726           
Files with missing lines Coverage Δ
beetsplug/fetchart.py 74.07% <100.00%> (+0.21%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

fetchart fetchart plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fetchart: permissions errors result in a crash, needs graceful fallback

2 participants