Skip to content

Commit 41f9876

Browse files
committed
[ModelicaSystem.getSolution()] do not try to continue on error but fail
Rule: fail early, fail hard - tell the user that something is wrong! In this case, the user ask for the solution but could get None (= plain 'return') - this would case hard to track errors later (if verbose==False and raiseerrors==False)
1 parent d9643e5 commit 41f9876

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

OMPython/ModelicaSystem.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -760,29 +760,24 @@ def getSolutions(self, varList=None, resultfile=None): # 12
760760

761761
# check for result file exits
762762
if not os.path.exists(resFile):
763-
errstr = f"Error: Result file does not exist {resFile}"
764-
self._raise_error(errstr=errstr)
765-
return
763+
raise ModelicaSystemError(f"Result file does not exist {resFile}")
766764
resultVars = self.sendExpression(f'readSimulationResultVars("{resFile}")')
767765
self.sendExpression("closeSimulationResultFile()")
768766
if varList is None:
769767
return resultVars
770768
elif isinstance(varList, str):
771769
if varList not in resultVars and varList != "time":
772-
self._raise_error(errstr=f'!!! {varList} does not exist')
773-
return
770+
raise ModelicaSystemError(f"Requested data {repr(varList)} does not exist")
774771
res = self.sendExpression(f'readSimulationResult("{resFile}", {{{varList}}})')
775772
npRes = np.array(res)
776773
self.sendExpression("closeSimulationResultFile()")
777774
return npRes
778775
elif isinstance(varList, list):
779-
# varList, = varList
780-
for v in varList:
781-
if v == "time":
776+
for var in varList:
777+
if var == "time":
782778
continue
783-
if v not in resultVars:
784-
self._raise_error(errstr=f'!!! {v} does not exist')
785-
return
779+
if var not in resultVars:
780+
raise ModelicaSystemError(f"Requested data {repr(var)} does not exist")
786781
variables = ",".join(varList)
787782
res = self.sendExpression(f'readSimulationResult("{resFile}",{{{variables}}})')
788783
npRes = np.array(res)
@@ -823,7 +818,8 @@ def apply_single(args1):
823818
return True
824819

825820
else:
826-
self._raise_error(errstr=f'"{value[0]}" is not a {args3} variable')
821+
raise ModelicaSystemError("Unhandled case in setMethodHelper.apply_single() - "
822+
f"{repr(value[0])} is not a {repr(args3)} variable")
827823

828824
result = []
829825
if isinstance(args1, str):

0 commit comments

Comments
 (0)