From b24dca62bd14ec902ea1e88b575d820f02fcce84 Mon Sep 17 00:00:00 2001 From: ewuerger Date: Tue, 22 Oct 2024 16:26:19 +0200 Subject: [PATCH] fix: Raise an exception when left and right are the same --- capellambse_context_diagrams/collectors/exchanges.py | 6 ++++++ capellambse_context_diagrams/errors.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/capellambse_context_diagrams/collectors/exchanges.py b/capellambse_context_diagrams/collectors/exchanges.py index 8f7ff12..0d425d7 100644 --- a/capellambse_context_diagrams/collectors/exchanges.py +++ b/capellambse_context_diagrams/collectors/exchanges.py @@ -163,6 +163,12 @@ def get_left_and_right(self) -> None: self.data.children.append(self.left) assert self.right is not None self.data.children.append(self.right) + if self.left == self.right: + raise errors.CycleError( + "The interface is a cycle, connecting the same " + "source and target." + ) + except AttributeError as error: logger.exception("Interface collection failed: \n%r", str(error)) diff --git a/capellambse_context_diagrams/errors.py b/capellambse_context_diagrams/errors.py index c557c5b..c164546 100644 --- a/capellambse_context_diagrams/errors.py +++ b/capellambse_context_diagrams/errors.py @@ -6,3 +6,7 @@ class CapellambseError(Exception): """Error raised by capellambse.""" + + +class CycleError(CapellambseError): + """Error raised when a cycle is detected."""