Handle ValueError when setting incorrect type
[mudpy.git] / mudpy / misc.py
index 2923feb..470fb96 100644 (file)
@@ -154,6 +154,8 @@ class Element:
 
     def set(self, facet, value):
         """Set values."""
+        if facet in ["loglevel"]:
+            value = int(value)
         if not self.has_facet(facet) or not self.get(facet) == value:
             if self.old_style:
                 if self.key not in self.origin.data:
@@ -2282,11 +2284,17 @@ def command_set(actor, parameters):
             if element not in universe.contents:
                 message = "The \"" + element + "\" element does not exist."
             else:
-                universe.contents[element].set(facet, value)
-                message = ("You have successfully (re)set the \"" + facet
-                           + "\" facet of element \"" + element
-                           + "\". Try \"show element " +
-                           element + "\" for verification.")
+                try:
+                    universe.contents[element].set(facet, value)
+                except ValueError:
+                    message = ("Value \"%s\" of type \"%s\" cannot be coerced "
+                               "to the correct datatype for facet \"%s\"." %
+                               (value, type(value), facet))
+                else:
+                    message = ("You have successfully (re)set the \"" + facet
+                               + "\" facet of element \"" + element
+                               + "\". Try \"show element " +
+                               element + "\" for verification.")
     actor.send(message)