From 2b05e637c849128bc1cd866292cd2eacef8f97a4 Mon Sep 17 00:00:00 2001 From: Adrian Pop Date: Fri, 6 Nov 2026 22:45:33 +0100 Subject: [PATCH] Accept filename and fileName in omc messages getMessagesStringInternal() prints the file of a message as filename = "..." in older omc versions and as fileName = "..." after OpenModelica/OpenModelica#17893 (issue OpenModelica/OpenModelica#17891). With only filename in the regex, the messages of a newer omc are not parsed, and an omc error does not raise OMSessionException. Accept both names. The new test checks that an omc error raises OMSessionException with the file name of the message. Co-Authored-By: Claude Opus 5.5 --- OMPython/om_session_omc.py | 2 +- tests/test_OMSessionCmd.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/OMPython/om_session_omc.py b/OMPython/om_session_omc.py index e1d0e461..de128913 100644 --- a/OMPython/om_session_omc.py +++ b/OMPython/om_session_omc.py @@ -466,7 +466,7 @@ def sendExpression(self, expr: str, parsed: bool = True, raise_on_error: bool = if not self._re_log_raw: self._re_log_raw = re.compile( pattern=r"\s*info = record OpenModelica\.Scripting\.SourceInfo\n" - r"\s*filename = \"(.*?)\",\n" + r"\s*file[nN]ame = \"(.*?)\",\n" # older omc: filename, newer: fileName r"\s*readonly = (.*?),\n" r"\s*lineStart = (\d+),\n" r"\s*columnStart = (\d+),\n" diff --git a/tests/test_OMSessionCmd.py b/tests/test_OMSessionCmd.py index 7dbb9705..dfcb19db 100644 --- a/tests/test_OMSessionCmd.py +++ b/tests/test_OMSessionCmd.py @@ -1,3 +1,5 @@ +import pytest + import OMPython @@ -18,3 +20,10 @@ def test_isPackage2(): # TODO: add more checks ... + + +def test_error_message_file(): + # omc names the file field of a message filename or fileName (OpenModelica issue 17891) + omcs = OMPython.OMCSessionLocal() + with pytest.raises(OMPython.OMSessionException, match=r"\[bad\.mo:"): + omcs.sendExpression('loadString("model M Real x = ; end M;", "bad.mo")')