Skip to content

Commit fb6ee69

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 97ded58 commit fb6ee69

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
@@ -674,29 +674,24 @@ def getSolutions(self, varList=None, resultfile=None): # 12
674674

675675
# check for result file exits
676676
if not os.path.exists(resFile):
677-
errstr = f"Error: Result file does not exist {resFile}"
678-
self._raise_error(errstr=errstr)
679-
return
677+
raise ModelicaSystemError(f"Result file does not exist {resFile}")
680678
resultVars = self.sendExpression(f'readSimulationResultVars("{resFile}")')
681679
self.sendExpression("closeSimulationResultFile()")
682680
if varList is None:
683681
return resultVars
684682
elif isinstance(varList, str):
685683
if varList not in resultVars and varList != "time":
686-
self._raise_error(errstr=f'!!! {varList} does not exist')
687-
return
684+
raise ModelicaSystemError(f"Requested data {repr(varList)} does not exist")
688685
res = self.sendExpression(f'readSimulationResult("{resFile}", {{{varList}}})')
689686
npRes = np.array(res)
690687
self.sendExpression("closeSimulationResultFile()")
691688
return npRes
692689
elif isinstance(varList, list):
693-
# varList, = varList
694-
for v in varList:
695-
if v == "time":
690+
for var in varList:
691+
if var == "time":
696692
continue
697-
if v not in resultVars:
698-
self._raise_error(errstr=f'!!! {v} does not exist')
699-
return
693+
if var not in resultVars:
694+
raise ModelicaSystemError(f"Requested data {repr(var)} does not exist")
700695
variables = ",".join(varList)
701696
res = self.sendExpression(f'readSimulationResult("{resFile}",{{{variables}}})')
702697
npRes = np.array(res)
@@ -737,7 +732,8 @@ def apply_single(args1):
737732
return True
738733

739734
else:
740-
self._raise_error(errstr=f'"{value[0]}" is not a {args3} variable')
735+
raise ModelicaSystemError("Unhandled case in setMethodHelper.apply_single() - "
736+
f"{repr(value[0])} is not a {repr(args3)} variable")
741737

742738
result = []
743739
if isinstance(args1, str):

0 commit comments

Comments
 (0)