Commit 5392f5b7 authored by Georg Krause's avatar Georg Krause
Browse files

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 !13
parents c1461b2e 63cd47d3
Pipeline #15868 passed with stages
in 2 minutes and 10 seconds
......@@ -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):
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment