Creating `Observables` in a python session might crash the interpreter.
kain88-de opened this issue · comments
BioEn/bioen/analyze/observables/observables.py
Lines 265 to 268 in 1927780
This is a hard exit of the python interpreter. When using BioEn as a library (e.g. in a notebook) it can crash the process instead of failing gracefully. To fail gracefully an exception should be raised.
To maintain well-formatted error messages in the CLI tool one can use try-except in the main
function
try:
obs = function_that_can_raise()
except Exception as e:
print("Exception occurred")
print("Error Message: ")
print(e)
if verbose:
raise(e) # to show stacktrace
sys.exit(1) # show tool exited with an error with return-code 1
Here are more cases that can unexpectedly kill the python process.
BioEn/bioen/optimize/forces.py
Line 422 in 1927780
BioEn/bioen/optimize/forces.py
Line 481 in 1927780
BioEn/bioen/optimize/forces.py
Line 485 in 1927780
BioEn/bioen/optimize/forces.py
Line 183 in 1927780
Here are all occurrences.
analyze/utils.py
32: sys.exit()
36: sys.exit()
optimize/log_weights.py
187: sys.exit(0)
423: sys.exit(0)
490: sys.exit(0)
494: sys.exit(0)
optimize/forces.py
183: sys.exit(0)
422: sys.exit(0)
481: sys.exit(0)
485: sys.exit(0)
analyze/observables/observables.py
268: sys.exit()
analyze/observables/deer/deer.py
119: sys.exit()
analyze/observables/scattering/scattering.py
119: sys.exit()
analyze/observables/generic/generic.py
93: sys.exit()
98: sys.exit()
This issue was fixed with v0.1.1:
- all sys.exit() calls were replaced by exceptions.
- the CLI tool run_bioen.main() catches these exceptions and prints their error message