Merge branch 'issue-17-invalid-lookup-uris' into 'master'

Add a nicer log entry when an invalid lookup URI is requested (#17)

Closes #17

See merge request funkwhale/mopidy!13
main
Georg Krause 2021-08-23 18:55:19 +00:00
commit 5392f5b705
2 changed files with 9 additions and 4 deletions

View File

@ -375,9 +375,14 @@ class FunkwhaleLibraryProvider(backend.LibraryProvider):
"artist": lambda id: client.list_tracks({"artist": id})["results"],
}
type, id = parse_uri(uri)
payload = config[type](id)
return [convert_to_track(row, cache=self.cache) for row in payload]
try:
type, id = parse_uri(uri)
except (IndexError, ValueError):
logger.info(f"Lookup failed: invalid uri '{uri}'")
return []
else:
payload = config[type](id)
return [convert_to_track(row, cache=self.cache) for row in payload]
def parse_uri(uri):

View File

@ -97,7 +97,7 @@ def test_parse_uri(uri, expected):
@pytest.mark.parametrize("type", ["track", "album", "artist"])
def test_parse_uri(type):
def test_to_ref(type):
obj = getattr(models, type.capitalize())(uri="hello:world", name="Hello")
expected = getattr(models.Ref, type)(uri=obj.uri, name=obj.name)
assert mopidy_funkwhale.library.to_ref(obj) == expected