From 1f17f8b745b3a537c63e79604a156b45b7596b82 Mon Sep 17 00:00:00 2001 From: AnHeuermann <38031952+AnHeuermann@users.noreply.github.com> Date: Thu, 13 Nov 2025 19:51:49 +0100 Subject: [PATCH] Catch loadModel errors - omc.sendExpression now throws OMCSessionException --- test.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test.py b/test.py index 1e66330..b046cc5 100755 --- a/test.py +++ b/test.py @@ -259,7 +259,7 @@ def target(): print("Error: Expected at least one configuration file to start the library test") sys.exit(1) -from OMPython import OMCSessionZMQ, OMCProcessDocker +from OMPython import OMCSessionZMQ, OMCProcessDocker, OMCSessionException # Try to make the processes a bit nicer... os.environ["GC_MARKERS"]="1" @@ -663,7 +663,9 @@ def hashReferenceFiles(s): raise Exception("Library %s has both libraryVersionLatestInPackageManager:true and libraryVersionExactMatch:true! Make up your mind." % libName) exactMatch=', requireExactVersion=true' - if not omc.sendExpression('loadModel(%s,%s%s)' % (lib,versions,exactMatch)): + try: + omc.sendExpression('loadModel(%s,%s%s)' % (lib,versions,exactMatch)) + except OMCSessionException: try: print("Failed to load library %s %s: %s" % (library,versions,omc.sendExpression('OpenModelica.Scripting.getErrorString()'))) except: @@ -726,7 +728,7 @@ def hashReferenceFiles(s): if conf.get("fmi") and fmisimulatorversion: conf["libraryVersionRevision"] = conf["libraryVersionRevision"] + " " + fmisimulatorversion.decode("ascii") conf["libraryLastChange"] = conf["libraryLastChange"] + " " + fmisimulatorversion.decode("ascii") - res=omc.sendExpression('{c for c guard isExperiment(c) and not regexBool(typeNameString(x), "^Modelica_Synchronous\\.WorkInProgress") in getClassNames(%s, recursive=true)}' % library) + res=omc.sendExpression('{c for c guard isExperiment(c) and not regexBool(typeNameString(x), "^Modelica_Synchronous\\\\.WorkInProgress") in getClassNames(%s, recursive=true)}' % library) if conf.get("ignoreModelPrefix"): if isinstance(conf["ignoreModelPrefix"], list): prefixes = conf["ignoreModelPrefix"]