Skip to content

Commit 6ef9359

Browse files
committed
musicbrainz: remove error handling
1 parent b469788 commit 6ef9359

File tree

1 file changed

+19
-60
lines changed

1 file changed

+19
-60
lines changed

beetsplug/musicbrainz.py

Lines changed: 19 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
from __future__ import annotations
1818

19-
import traceback
2019
from collections import Counter
2120
from contextlib import suppress
2221
from dataclasses import dataclass
@@ -25,7 +24,6 @@
2524
from typing import TYPE_CHECKING, Any, Iterable, Sequence
2625
from urllib.parse import urljoin
2726

28-
import musicbrainzngs
2927
from confuse.exceptions import NotFoundError
3028
from requests_ratelimiter import LimiterMixin
3129

@@ -64,24 +62,6 @@ class LimiterTimeoutSession(LimiterMixin, TimeoutSession):
6462
pass
6563

6664

67-
musicbrainzngs.set_useragent("beets", beets.__version__, "https://beets.io/")
68-
69-
70-
class MusicBrainzAPIError(util.HumanReadableError):
71-
"""An error while talking to MusicBrainz. The `query` field is the
72-
parameter to the action and may have any type.
73-
"""
74-
75-
def __init__(self, reason, verb, query, tb=None):
76-
self.query = query
77-
if isinstance(reason, musicbrainzngs.WebServiceError):
78-
reason = "MusicBrainz not reachable"
79-
super().__init__(reason, verb, tb)
80-
81-
def get_message(self):
82-
return f"{self._reasonstr()} in {self.verb} with query {self.query!r}"
83-
84-
8565
RELEASE_INCLUDES = [
8666
"artists",
8767
"media",
@@ -810,15 +790,9 @@ def _search_api(
810790
self._log.debug(
811791
"Searching for MusicBrainz {}s with: {!r}", query_type, query
812792
)
813-
try:
814-
res = self.api._get(
815-
query_type, query=query, limit=self.config["search_limit"].get()
816-
)
817-
except musicbrainzngs.MusicBrainzError as exc:
818-
raise MusicBrainzAPIError(
819-
exc, f"{query_type} search", filters, traceback.format_exc()
820-
)
821-
return res[f"{query_type}s"]
793+
return self.api._get(
794+
query_type, query=query, limit=self.config["search_limit"].get()
795+
)[f"{query_type}s"]
822796

823797
def candidates(
824798
self,
@@ -856,29 +830,20 @@ def album_for_id(
856830
self._log.debug("Invalid MBID ({}).", album_id)
857831
return None
858832

859-
try:
860-
res = self.api.get_release(albumid)
833+
res = self.api.get_release(albumid)
861834

862-
# resolve linked release relations
863-
actual_res = None
835+
# resolve linked release relations
836+
actual_res = None
864837

865-
if res.get("status") == "Pseudo-Release" and (
866-
relations := res.get("relations")
867-
):
868-
for rel in relations:
869-
if (
870-
rel["type"] == "transl-tracklisting"
871-
and rel["direction"] == "backward"
872-
):
873-
actual_res = self.api.get_release(rel["target"])
874-
875-
except musicbrainzngs.ResponseError:
876-
self._log.debug("Album ID match failed.")
877-
return None
878-
except musicbrainzngs.MusicBrainzError as exc:
879-
raise MusicBrainzAPIError(
880-
exc, "get release by ID", albumid, traceback.format_exc()
881-
)
838+
if res.get("status") == "Pseudo-Release" and (
839+
relations := res.get("relations")
840+
):
841+
for rel in relations:
842+
if (
843+
rel["type"] == "transl-tracklisting"
844+
and rel["direction"] == "backward"
845+
):
846+
actual_res = self.api.get_release(rel["target"])
882847

883848
# release is potentially a pseudo release
884849
release = self.album_info(res)
@@ -900,13 +865,7 @@ def track_for_id(
900865
self._log.debug("Invalid MBID ({}).", track_id)
901866
return None
902867

903-
try:
904-
res = self.api.get_recording(trackid)
905-
except (HTTPNotFoundError, musicbrainzngs.ResponseError):
906-
self._log.debug("Track ID match failed.")
907-
return None
908-
except musicbrainzngs.MusicBrainzError as exc:
909-
raise MusicBrainzAPIError(
910-
exc, "get recording by ID", trackid, traceback.format_exc()
911-
)
912-
return self.track_info(res)
868+
with suppress(HTTPNotFoundError):
869+
return self.track_info(self.api.get_recording(trackid))
870+
871+
return None

0 commit comments

Comments
 (0)