jerbaroo / bridge-sim

Python library for concrete slab bridge simulation.
MIT License
1 stars 0 forks source link

Add more informative error messages when OS fails to run #172

Closed rozsasarpi closed 3 years ago

rozsasarpi commented 3 years ago

Problems

  1. On Windows machines even if the path to OS is provided (os_exe), the OS analysis will not run but a permission error is raised.
  2. If fem_runner.exe_path is None the error message is a bit cryptic:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.3\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.3\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/arpada/Working_folder/2020/ERP_DT/bridge-sim/example.py", line 10, in <module>
    responses = sim.responses.load(config, model.RT.YTrans, point_loads)
  File "c:\users\arpada\working_folder\2020\erp_dt\bridge-sim\src\bridge_sim\sim\responses\__init__.py", line 56, in load
    return load_fem_responses(
  File "c:\users\arpada\working_folder\2020\erp_dt\bridge-sim\src\bridge_sim\sim\run\__init__.py", line 252, in load_fem_responses
    c.sim_runner.run(c, [sim_params])
  File "c:\users\arpada\working_folder\2020\erp_dt\bridge-sim\src\bridge_sim\sim\run\__init__.py", line 99, in run
    expt_params = self._run(config, expt_params, self, sim_ind)
  File "c:\users\arpada\working_folder\2020\erp_dt\bridge-sim\src\bridge_sim\sim\run\opensees\run.py", line 17, in run_model
    subprocess.run(
  File "c:\users\arpada\appdata\local\programs\python\python38-32\lib\subprocess.py", line 489, in run
    with Popen(*popenargs, **kwargs) as process:
  File "c:\users\arpada\appdata\local\programs\python\python38-32\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "c:\users\arpada\appdata\local\programs\python\python38-32\lib\subprocess.py", line 1247, in _execute_child
    args = list2cmdline(args)
  File "c:\users\arpada\appdata\local\programs\python\python38-32\lib\subprocess.py", line 549, in list2cmdline
    for arg in map(os.fsdecode, seq):
  File "c:\users\arpada\appdata\local\programs\python\python38-32\lib\os.py", line 818, in fsdecode
    filename = fspath(filename)  # Does type-checking of `filename`.
TypeError: expected str, bytes or os.PathLike object, not NoneType

Proposed solution

  1. I could make it work on Windows only by adding the path to os_exe to $PATH -> the permission error is caught and a suggestion to add to $PATH is given
  2. Raise a specific error: No OpenSees exe is found on the $PATH, nor a path (os_exe) is provided by the user!

Tested on Windows 10 and python 3.8.5.

jerbaroo commented 3 years ago

Thank your for the PR!

For point number 2, I have pushed code to master such that the error will be raised when constructing an instance of the OSRunner class. This means the error will be raised as early as possible, instead of waiting until the FE model file is built.

jerbaroo commented 3 years ago

Regarding point number 1, I have moved the try/except to here such that it is not specific to OpenSees, replacing "opensees.exe" with f"{self.name} executable".

@rozsasarpi you check that point 1 and 2 are both addressed in this branch alstublieft?