Skip to content

Commit 835a765

Browse files
committed
Fix incorrect use of IOError
When IOError constructor is called with two arguments, the first argument is interpreted as the error number: In [1]: str(IOError("/test1", "does not exist")) Out[1]: '[Errno /test1] does not exist'
1 parent 83d5386 commit 835a765

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,12 +472,12 @@ def setTempDirectory(self, customBuildDirectory: Optional[str | os.PathLike | pa
472472
# create a unique temp directory for each session and build the model in that directory
473473
if customBuildDirectory is not None:
474474
if not os.path.exists(customBuildDirectory):
475-
raise IOError(customBuildDirectory, " does not exist")
475+
raise IOError(f"{customBuildDirectory} does not exist")
476476
tempdir = pathlib.Path(customBuildDirectory)
477477
else:
478478
tempdir = pathlib.Path(tempfile.mkdtemp())
479479
if not tempdir.is_dir():
480-
raise IOError(tempdir, " cannot be created")
480+
raise IOError(f"{tempdir} could not be created")
481481

482482
logger.info("Define tempdir as %s", tempdir)
483483
exp = f'cd("{tempdir.absolute().as_posix()}")'
@@ -1235,8 +1235,10 @@ def load_module_from_path(module_name, file_path):
12351235
return module_def
12361236

12371237
if self.xmlFile is None:
1238-
raise IOError("Linearization cannot be performed as the model is not build, "
1239-
"use ModelicaSystem() to build the model first")
1238+
raise ModelicaSystemError(
1239+
"Linearization cannot be performed as the model is not build, "
1240+
"use ModelicaSystem() to build the model first"
1241+
)
12401242

12411243
om_cmd = ModelicaSystemCmd(runpath=self.tempdir, modelname=self.modelName, timeout=timeout)
12421244

0 commit comments

Comments
 (0)