Skip to content

mbcollection: handle MB Unauthorized error#6661

Open
snejus wants to merge 2 commits into
masterfrom
handle-mb-unauthorized-error
Open

mbcollection: handle MB Unauthorized error#6661
snejus wants to merge 2 commits into
masterfrom
handle-mb-unauthorized-error

Conversation

@snejus
Copy link
Copy Markdown
Member

@snejus snejus commented May 21, 2026

PR Summary

This change makes mbupdate fail gracefully when MusicBrainz returns 401 Unauthorized.

High-level impact

  • Adds a MusicBrainz-specific HTTP error, UnauthorizedMBError, on top of the shared BeetsHTTPError request layer.
  • Registers that error in MusicBrainzAPI, so authentication failures are translated into a clearer domain-specific exception.
  • Updates beetsplug/mbcollection.py to catch BeetsHTTPError during collection sync and log a user-friendly error instead of crashing.
  • Adds a regression test covering the unauthorized case and documents the behavior in docs/changelog.rst.

Architectural effect

  • Keeps HTTP-to-domain error mapping centralized in beetsplug/_utils/musicbrainz.py and beetsplug/_utils/requests.py.
  • Keeps mbcollection focused on sync flow and error handling, rather than raw HTTP details.
  • Improves resilience of the mbcollection plugin without changing the normal successful update path.

Fixes #6651

@snejus snejus requested a review from a team as a code owner May 21, 2026 19:27
Copilot AI review requested due to automatic review settings May 21, 2026 19:27
@github-actions github-actions Bot added the mbcollection mbcollection plugin label May 21, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

❌ Patch coverage is 96.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 72.48%. Comparing base (6dd6251) to head (96639ad).

Files with missing lines Patch % Lines
beetsplug/mbcollection.py 92.30% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6661      +/-   ##
==========================================
+ Coverage   72.46%   72.48%   +0.01%     
==========================================
  Files         161      161              
  Lines       20719    20731      +12     
  Branches     3280     3280              
==========================================
+ Hits        15014    15026      +12     
  Misses       4979     4979              
  Partials      726      726              
Files with missing lines Coverage Δ
beetsplug/_utils/musicbrainz.py 97.35% <100.00%> (+0.05%) ⬆️
beetsplug/_utils/requests.py 97.75% <100.00%> (+0.02%) ⬆️
beetsplug/mbcollection.py 93.20% <92.30%> (+0.27%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

grug see PR make mbcollection not crash when MusicBrainz say 401 Unauthorized. grug like: plugin now catch nice beets HTTP error, log clear hint for user config, then keep program alive.

Changes:

  • add MusicBrainz-specific UnauthorizedMBError and register it in MusicBrainzAPI HTTP error mapping
  • catch BeetsHTTPError in mbcollection sync flow and log friendly error instead of raising up to importer
  • add regression test and changelog note for 401 behavior

Reviewed changes

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

Show a summary per file
File Description
beetsplug/_utils/requests.py allow BeetsHTTPError to accept custom message so domain errors can give better text
beetsplug/_utils/musicbrainz.py define UnauthorizedMBError (401) and register in MusicBrainz API handler
beetsplug/mbcollection.py catch BeetsHTTPError during collection update and log error instead of crash
test/plugins/test_mbcollection.py add test that mbupdate logs unauthorized failure
docs/changelog.rst document bugfix for mbcollection unauthorized case

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

Labels

mbcollection mbcollection plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

importer crashes due to mbcollection error

2 participants