|
46 | 46 | from dataclasses import dataclass |
47 | 47 | from typing import Optional |
48 | 48 |
|
49 | | -from OMPython.OMCSession import OMCSessionBase, OMCSessionZMQ |
| 49 | +from OMPython.OMCSession import OMCSessionBase, OMCSessionZMQ, OMCSessionException |
50 | 50 |
|
51 | 51 | # define logger using the current module name as ID |
52 | 52 | logger = logging.getLogger(__name__) |
@@ -369,16 +369,10 @@ def buildModel(self, variableFilter=None): |
369 | 369 | self.xmlparse() |
370 | 370 |
|
371 | 371 | def sendExpression(self, expr, parsed=True): |
372 | | - logger.debug("sendExpression(%r, %r)", expr, parsed) |
373 | | - # TODO: add correct error handling |
374 | 372 | try: |
375 | 373 | 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 |
382 | 376 | return retval |
383 | 377 |
|
384 | 378 | # request to OMC |
@@ -1148,7 +1142,6 @@ def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = N |
1148 | 1142 | linearFile = pathlib.Path(f'linear_{self.modelName}.py') |
1149 | 1143 |
|
1150 | 1144 | if not linearFile.exists(): |
1151 | | - errormsg = self.sendExpression("getErrorString()") |
1152 | 1145 | raise ModelicaSystemError(f"Linearization failed: {linearFile} not found: {errormsg}") |
1153 | 1146 |
|
1154 | 1147 | # this function is called from the generated python code linearized_model.py at runtime, |
|
0 commit comments