From 1c6a9e2c49797a6f58319fd1822f4b4c70df0438 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 9 May 2024 16:08:41 +0500 Subject: [PATCH] more descriptive errors settings incorrect data type to attributes Example: ``` ifc_file = ifcopenshell.file(schema="IFC2X3") entity = ifc_file.create_entity("IfcCostSchedule") entity.UpdateDate = ifcopenshell.util.date.datetime2ifc(datetime.now(), "IfcDateTime") ``` --- .../ifcopenshell/entity_instance.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/entity_instance.py b/src/ifcopenshell-python/ifcopenshell/entity_instance.py index 499c1a260e..de3ce535a6 100644 --- a/src/ifcopenshell-python/ifcopenshell/entity_instance.py +++ b/src/ifcopenshell-python/ifcopenshell/entity_instance.py @@ -338,7 +338,18 @@ class entity_instance: ) raise e else: - self.method_list[idx](self.wrapped_data, idx, entity_instance.unwrap_value(value)) + try: + self.method_list[idx](self.wrapped_data, idx, entity_instance.unwrap_value(value)) + except TypeError: + raise TypeError( + "attribute '%s' for entity '%s' is expecting value of type '%s', got '%s'." + % ( + self.wrapped_data.get_argument_name(idx), + self.wrapped_data.is_a(True), + self.wrapped_data.get_argument_type(idx), + type(value).__name__, + ) + ) return value