Skip to content

Finish error handling #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 22, 2025
Merged

Conversation

syntron
Copy link
Contributor

@syntron syntron commented May 1, 2025

Finish update of error handling in OMSession.py and ModelicaSystem.py

Based on PR #277, #273 and #270

Changes

  • Always check for errors in sendExpression()
  • align logging - log data only once
  • cleanup

This was referenced May 1, 2025
@syntron syntron force-pushed the finish_error_handling branch from 5377e62 to 47cd01b Compare May 3, 2025 19:34
@syntron syntron mentioned this pull request May 6, 2025
@adeas31
Copy link
Member

adeas31 commented May 6, 2025

Rebase this one and see if you can use getMessagesStringInternal(). We should also check if expression is getErrorString() or getMessagesStringInternal() then we should not call it twice.

@syntron
Copy link
Contributor Author

syntron commented May 7, 2025

@adeas31 would it be possible to merge #281 and #282 before that? Both would merge in this order without problems even if not rebased.

This would simplify the merge as this PR is based on these two. Furthermore, I will be limited in time till mid of next week ...

@syntron
Copy link
Contributor Author

syntron commented May 7, 2025

@adeas31 do you have a simple way / an example to force an error? I would like to check how to evaluate the output of getMessagesStringInternal()

@adeas31
Copy link
Member

adeas31 commented May 7, 2025

Run the following script with omc,

loadString("model M Real foo = \"str\"; annotation (uses(Modelica(version=\"4.0.0\"))); end M;");
getMessagesStringInternal();
checkModel(M);
getMessagesStringInternal();

equivalent OMPython code is,

from OMPython import OMCSessionZMQ
omc = OMCSessionZMQ()
omc.sendExpression("model M Real foo = \"str\"; annotation (uses(Modelica(version=\"4.0.0\"))); end M;")
omc.sendExpression("getMessagesStringInternal()")
omc.sendExpression("checkModel(M)")
omc.sendExpression("getMessagesStringInternal()")

The first call to getMessagesStringInternal() gives the notificaitons caused by loading model M, the second call gives the error caused by calling checkModel(M).
Note. I haven't tried running the python code but I guess it will work.

You can also see how getMessagesStringInternal() is used in OMEdit here https://github.com/OpenModelica/OpenModelica/blob/master/OMEdit/OMEditLIB/OMC/OMCProxy.cpp#L611

@syntron syntron force-pushed the finish_error_handling branch 2 times, most recently from 8f6d05d to 31ef902 Compare May 8, 2025 20:26
@adeas31
Copy link
Member

adeas31 commented May 9, 2025

Let me know once its ready for review.

@syntron syntron force-pushed the finish_error_handling branch from 31ef902 to fe5f3e3 Compare May 9, 2025 19:03
@syntron
Copy link
Contributor Author

syntron commented May 9, 2025

Let me know once its ready for review.

@adeas31 all done including getMessagesStringInternal() in this PR

Please use the following order for review: PR #281, PR #282 (needs a simple conflict solution), PR #278

PR #279 is currently not updated as it would be on top of PR #278

Besides these, there are some smaller cleanups pending

@syntron syntron force-pushed the finish_error_handling branch from 08d1007 to 5d9b182 Compare May 12, 2025 16:16
@adeas31
Copy link
Member

adeas31 commented May 20, 2025

All the dependent PRs are merged. Lets rebase this one now.

@syntron syntron force-pushed the finish_error_handling branch from 5d9b182 to 4d8a0e7 Compare May 20, 2025 19:23
@syntron
Copy link
Contributor Author

syntron commented May 20, 2025

@adeas31 ready to go ...

Copy link
Member

@adeas31 adeas31 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@@ -325,6 +326,9 @@ def __init__(self, timeout=10.00,
# connect to the running omc instance using ZMQ
self._connect_to_omc(timeout)

self._re_log_entries = None
self._re_log_raw = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to make them class members?

error_raw = self._omc.recv_string()
# run error handling only if there is something to check
if error_raw != "{}\n":
if not self._re_log_entries:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self._re_log_entries and self._re_log_raw can be local variables here.

Copy link
Contributor Author

@syntron syntron May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I defined them as class variables to do the initialisation once (if needed at all). Later, the compiled re struture is just reused ... However, if the expected numbers of calls to this part is low, it makes sense to run this each time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual re compilation is run each time, its just they are initialized to none only once. I don't think initializing them to none locally is expensive.

Copy link
Contributor Author

@syntron syntron May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in OMCSession.py line 584ff (definition of sendExpression()):

if not self._re_log_entries:
    self._re_log_entries = re.compile(...)

if not self._re_log_raw:
    self._re_log_raw = re.compile(...)

Compilation is done only once (on first call; self._re* class variables are None); after that, the variables are set (not None) and, thus, the compiled version is used ...

@syntron syntron force-pushed the finish_error_handling branch from 4d8a0e7 to 94ec48b Compare May 21, 2025 16:50
@adeas31 adeas31 merged commit 64a16ef into OpenModelica:master May 22, 2025
5 checks passed
@syntron syntron deleted the finish_error_handling branch May 22, 2025 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants