From f3b3e2a44110f7e154fc4a3b2b33ecfc6c2a2006 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Fri, 6 Oct 2017 16:02:34 +0200 Subject: [PATCH] More meaningful error message setting attributes in python --- src/ifcopenshell-python/ifcopenshell/entity_instance.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/entity_instance.py b/src/ifcopenshell-python/ifcopenshell/entity_instance.py index ac6621ee73..34b72e8de5 100644 --- a/src/ifcopenshell-python/ifcopenshell/entity_instance.py +++ b/src/ifcopenshell-python/ifcopenshell/entity_instance.py @@ -88,14 +88,17 @@ class entity_instance(object): if value is None: self.wrapped_data.setArgumentAsNull(idx) else: - attr_type = self.attribute_type(idx).title().replace(' ', '') + attr_type = real_attr_type = self.attribute_type(idx).title().replace(' ', '') attr_type = attr_type.replace('Binary', 'String') attr_type = attr_type.replace('Enumeration', 'String') try: if isinstance(value, unicode): value = value.encode("utf-8") except: pass - getattr(self.wrapped_data, "setArgumentAs%s" % attr_type)(idx, entity_instance.unwrap_value(value)) + try: + getattr(self.wrapped_data, "setArgumentAs%s" % attr_type)(idx, entity_instance.unwrap_value(value)) + except: + raise ValueError("Expected %s for attribute %s.%s, got %r" % (real_attr_type, self.is_a(), self.attribute_name(idx), value)) return value def __len__(self):