From 91199308a9fe591895caef37c0fe90b232ead2f1 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 20 Feb 2024 15:19:09 +0500 Subject: [PATCH] descriptive error for missing user or application in ifc2x3 #4340 --- .../api/owner/create_owner_history.py | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/owner/create_owner_history.py b/src/ifcopenshell-python/ifcopenshell/api/owner/create_owner_history.py index 194e8812cf..c1aa37f986 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/owner/create_owner_history.py +++ b/src/ifcopenshell-python/ifcopenshell/api/owner/create_owner_history.py @@ -106,16 +106,26 @@ class Usecase: application = ifcopenshell.api.owner.settings.get_application(self.file) if self.file.schema != "IFC2X3" and not application: return - return self.file.create_entity( - "IfcOwnerHistory", - **{ - "OwningUser": user, - "OwningApplication": application, - "State": "READWRITE", - "ChangeAction": "ADDED", - "LastModifiedDate": int(time.time()), - "LastModifyingUser": user, - "LastModifyingApplication": application, - "CreationDate": int(time.time()), - }, - ) + try: + return self.file.create_entity( + "IfcOwnerHistory", + **{ + "OwningUser": user, + "OwningApplication": application, + "State": "READWRITE", + "ChangeAction": "ADDED", + "LastModifiedDate": int(time.time()), + "LastModifyingUser": user, + "LastModifyingApplication": application, + "CreationDate": int(time.time()), + }, + ) + except Exception as e: + # clarification message because error may come out of blue for users + # first time they try to create_entity in IFC2X3 + if self.file.schema == "IFC2X3" and (application is None or user is None): + raise Exception( + "In IFC2X3 setting up owner history mandatory but it cannot be setup because either user or application is not set. " + "See an example in the owner.create_owner_history documentation." + ) + raise e