Catch exceptions in YAML menus
authorJeremy Stanley <fungi@yuggoth.org>
Tue, 20 May 2014 08:40:10 +0000 (08:40 +0000)
committerJeremy Stanley <fungi@yuggoth.org>
Tue, 20 May 2014 08:40:10 +0000 (08:40 +0000)
* lib/mudpy/misc.py(Element.facets,Element.get): Early in login and
account creation, elements can have None in place of a dict for their
data. Under these circumstances, listing their keys throws
AttributeError and deep-linking into specific keys throws TypeError.
Catch these and treat them as empty.

lib/mudpy/misc.py

index 1f3909b..84d1a5e 100644 (file)
@@ -104,7 +104,7 @@ class Element:
         if self.origin._format == "yaml":
             try:
                 return self.origin.data[self.key].keys()
-            except KeyError:
+            except (AttributeError, KeyError):
                 return []
         else:
             if self.key in self.origin.data.sections():
@@ -143,7 +143,7 @@ class Element:
         if self.origin._format == "yaml":
             try:
                 return self.origin.data[self.key][facet]
-            except KeyError:
+            except (KeyError, TypeError):
                 pass
             if self.has_facet("inherit"):
                 for ancestor in self.ancestry():