diff src/memory/memory.py @ 1689:a40124e03baf

core (memory): catch exceptions.UnknownEntityError in getMainResource
author Goffi <goffi@goffi.org>
date Thu, 26 Nov 2015 17:00:18 +0100
parents 373ce871b0f3
children 35426d58471c
line wrap: on
line diff
--- a/src/memory/memory.py	Thu Nov 26 16:04:45 2015 +0100
+++ b/src/memory/memory.py	Thu Nov 26 17:00:18 2015 +0100
@@ -565,6 +565,7 @@
         return (list[unicode]): list of resources
 
         @raise exceptions.UnknownEntityError: if entity is not in cache
+        @raise ValueError: entity_jid has a resource
         """
         if entity_jid.resource:
             raise ValueError("getAllResources must be used with a bare jid (got {})".format(entity_jid))
@@ -618,7 +619,11 @@
                 return None  # MUC rooms have no main resource
         except KeyError:  # plugin not found
             pass
-        resources = self.getAllResources(entity_jid, profile_key)
+        try:
+            resources = self.getAllResources(entity_jid, profile_key)
+        except exceptions.UnknownEntityError:
+            log.warning(u"Entity is not in cache, we can't find any resource")
+            return None
         priority_resources = []
         for resource in resources:
             full_jid = copy.copy(entity_jid)