From 64df82a76ba8fb7b74323b2778e0f2acc0fe597d Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 7 May 2025 17:47:06 +0500 Subject: [PATCH] ifcopenshell.file - save last failed transaction for introspection --- src/ifcopenshell-python/ifcopenshell/file.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/file.py b/src/ifcopenshell-python/ifcopenshell/file.py index a4a4f3d679..134200a1e3 100644 --- a/src/ifcopenshell-python/ifcopenshell/file.py +++ b/src/ifcopenshell-python/ifcopenshell/file.py @@ -59,6 +59,12 @@ HEADER_FIELDS = { } +class UndoSystemError(Exception): + def __init__(self, message: str, transaction: Transaction): + super().__init__(message) + self.transaction = transaction + + class Transaction: def __init__(self, ifc_file: file): self.file: file = ifc_file @@ -342,14 +348,20 @@ class file: if not self.history: return transaction = self.history.pop() - transaction.rollback() + try: + transaction.rollback() + except Exception as e: + raise UndoSystemError("Error during transaction undo.", transaction) from e self.future.append(transaction) def redo(self) -> None: if not self.future: return transaction = self.future.pop() - transaction.commit() + try: + transaction.commit() + except Exception as e: + raise UndoSystemError("Error during transaction redo.", transaction) from e self.history.append(transaction) def create_entity(self, type: str, *args, **kwargs) -> ifcopenshell.entity_instance: