Log missing avatars
authorJeremy Stanley <fungi@yuggoth.org>
Thu, 6 Nov 2014 01:41:56 +0000 (01:41 +0000)
committerJeremy Stanley <fungi@yuggoth.org>
Thu, 6 Nov 2014 01:41:56 +0000 (01:41 +0000)
If an avatar is missing, it's likely that it was created but not yet
saved during a crash. This is usually safe to skip but could imply
data corruption, so log the situation with a high log level.

lib/mudpy/misc.py

index 8e747dd..ead6f54 100644 (file)
@@ -414,9 +414,13 @@ class Universe:
         # make a list of inactive avatars
         inactive_avatars = []
         for account in self.categories["account"].values():
-            inactive_avatars += [
-                (self.contents[x]) for x in account.getlist("avatars")
-            ]
+            for avatar in account.get("avatars"):
+                try:
+                    inactive_avatars.append(self.contents[avatar])
+                except KeyError:
+                    pending_loglines.append((
+                        "Missing avatar \"%s\", possible data corruption" %
+                        avatar, 6))
         for user in self.userlist:
             if user.avatar in inactive_avatars:
                 inactive_avatars.remove(user.avatar)
@@ -973,11 +977,14 @@ class User:
 
     def list_avatar_names(self):
         """List names of assigned avatars."""
-        return [
-            universe.contents[avatar].get(
-                "name"
-            ) for avatar in self.account.getlist("avatars")
-        ]
+        avatars = []
+        for avatar in self.account.get("avatars"):
+            try:
+                avatars.append(universe.contents[avatar].get("name"))
+            except KeyError:
+                log("Missing avatar \"%s\", possible data corruption." %
+                    avatar, 6)
+        return avatars
 
 
 def broadcast(message, add_prompt=True):