Skip to content

Commit 189fbd1

Browse files
committed
discogs: don't crash if a release is deleted
1 parent 0fec858 commit 189fbd1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

beetsplug/discogs.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import http.client
2222
import json
23+
import logging
2324
import os
2425
import re
2526
import socket
@@ -31,7 +32,7 @@
3132

3233
import confuse
3334
from discogs_client import Client, Master, Release
34-
from discogs_client.exceptions import DiscogsAPIError
35+
from discogs_client.exceptions import DiscogsAPIError, HTTPError
3536
from requests.exceptions import ConnectionError
3637
from typing_extensions import TypedDict
3738

@@ -46,6 +47,8 @@
4647
from collections.abc import Callable, Iterable
4748

4849
from beets.library import Item
50+
# Global logger.
51+
log = logging.getLogger("beets")
4952

5053
USER_AGENT = f"beets/{beets.__version__} +https://beets.io/"
5154
API_KEY = "rAzVUQYRaoFjeBjyWuWZ"
@@ -305,7 +308,13 @@ def get_album_info(self, result):
305308
# Explicitly reload the `Release` fields, as they might not be yet
306309
# present if the result is from a `discogs_client.search()`.
307310
if not result.data.get("artists"):
308-
result.refresh()
311+
try:
312+
result.refresh()
313+
except HTTPError as exc:
314+
if exc.status_code == 404:
315+
log.debug("Request not found: {0}: {1}", result, exc)
316+
else:
317+
raise
309318

310319
# Sanity check for required fields. The list of required fields is
311320
# defined at Guideline 1.3.1.a, but in practice some releases might be

0 commit comments

Comments
 (0)