Skip to content

Commit 5fea05b

Browse files
committed
??? [ModelicaSystem] simplify sendExpression()
1 parent 778f7c4 commit 5fea05b

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
from dataclasses import dataclass
4747
from typing import Optional
4848

49-
from OMPython.OMCSession import OMCSessionBase, OMCSessionZMQ
49+
from OMPython.OMCSession import OMCSessionBase, OMCSessionZMQ, OMCSessionException
5050

5151
# define logger using the current module name as ID
5252
logger = logging.getLogger(__name__)
@@ -369,16 +369,10 @@ def buildModel(self, variableFilter=None):
369369
self.xmlparse()
370370

371371
def sendExpression(self, expr, parsed=True):
372-
logger.debug("sendExpression(%r, %r)", expr, parsed)
373-
# TODO: add correct error handling
374372
try:
375373
retval = self.getconn.sendExpression(expr, parsed)
376-
except Exception as exc:
377-
# TODO: need OMCSessionException
378-
raise ModelicaSystemError(f"Error executing {repr(expr)}") from exc
379-
errstr = self.sendExpression("getErrorString()")
380-
if errstr:
381-
raise ModelicaSystemError(f"Error executing {repr(expr)} (parsed={parsed}): {errstr}")
374+
except OMCSessionException as ex:
375+
raise ModelicaSystemError(f"Error executing {repr(expr)}") from ex
382376
return retval
383377

384378
# request to OMC
@@ -1148,7 +1142,6 @@ def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = N
11481142
linearFile = pathlib.Path(f'linear_{self.modelName}.py')
11491143

11501144
if not linearFile.exists():
1151-
errormsg = self.sendExpression("getErrorString()")
11521145
raise ModelicaSystemError(f"Linearization failed: {linearFile} not found: {errormsg}")
11531146

11541147
# this function is called from the generated python code linearized_model.py at runtime,

0 commit comments

Comments
 (0)