core: Catch exceptions when browsing in backends
Also splits browse into to method to better distinguish the two possible code paths.
This commit is contained in:
parent
928b8df08c
commit
511cf4e326
@ -68,23 +68,30 @@ class LibraryController(object):
|
|||||||
|
|
||||||
.. versionadded:: 0.18
|
.. versionadded:: 0.18
|
||||||
"""
|
"""
|
||||||
if uri is None:
|
return self._roots() if uri is None else self._browse(uri)
|
||||||
directories = set()
|
|
||||||
backends = self.backends.with_library_browse.values()
|
|
||||||
futures = {b: b.library.root_directory for b in backends}
|
|
||||||
for backend, future in futures.items():
|
|
||||||
try:
|
|
||||||
directories.add(future.get())
|
|
||||||
except Exception:
|
|
||||||
logger.exception('%s backend caused an exception.',
|
|
||||||
backend.actor_ref.actor_class.__name__)
|
|
||||||
return sorted(directories, key=operator.attrgetter('name'))
|
|
||||||
|
|
||||||
|
def _roots(self):
|
||||||
|
directories = set()
|
||||||
|
backends = self.backends.with_library_browse.values()
|
||||||
|
futures = {b: b.library.root_directory for b in backends}
|
||||||
|
for backend, future in futures.items():
|
||||||
|
try:
|
||||||
|
directories.add(future.get())
|
||||||
|
except Exception:
|
||||||
|
logger.exception('%s backend caused an exception.',
|
||||||
|
backend.actor_ref.actor_class.__name__)
|
||||||
|
return sorted(directories, key=operator.attrgetter('name'))
|
||||||
|
|
||||||
|
def _browse(self, uri):
|
||||||
scheme = urlparse.urlparse(uri).scheme
|
scheme = urlparse.urlparse(uri).scheme
|
||||||
backend = self.backends.with_library_browse.get(scheme)
|
backend = self.backends.with_library_browse.get(scheme)
|
||||||
if not backend:
|
try:
|
||||||
return []
|
if backend:
|
||||||
return backend.library.browse(uri).get()
|
return backend.library.browse(uri).get() # TODO: sort?
|
||||||
|
except Exception:
|
||||||
|
logger.exception('%s backend caused an exception.',
|
||||||
|
backend.actor_ref.actor_class.__name__)
|
||||||
|
return []
|
||||||
|
|
||||||
def get_distinct(self, field, query=None):
|
def get_distinct(self, field, query=None):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -444,10 +444,9 @@ class BackendFailuresCoreLibraryTest(unittest.TestCase):
|
|||||||
logger.exception.assert_called_with(mock.ANY, 'DummyBackend')
|
logger.exception.assert_called_with(mock.ANY, 'DummyBackend')
|
||||||
|
|
||||||
def test_browse_backend_browse_uri_exception_gets_through(self, logger):
|
def test_browse_backend_browse_uri_exception_gets_through(self, logger):
|
||||||
# TODO: is this behavior desired?
|
|
||||||
self.library.browse.return_value.get.side_effect = Exception
|
self.library.browse.return_value.get.side_effect = Exception
|
||||||
with self.assertRaises(Exception):
|
self.assertEqual([], self.core.library.browse('dummy:directory'))
|
||||||
self.core.library.browse('dummy:directory')
|
logger.exception.assert_called_with(mock.ANY, 'DummyBackend')
|
||||||
|
|
||||||
def test_get_distinct_backend_exception_gets_ignored(self, logger):
|
def test_get_distinct_backend_exception_gets_ignored(self, logger):
|
||||||
self.library.get_distinct.return_value.get.side_effect = Exception
|
self.library.get_distinct.return_value.get.side_effect = Exception
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user