Handle ValueError when setting incorrect type
[mudpy.git] / mudpy / misc.py
index 6cb7804..470fb96 100644 (file)
@@ -2284,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)