bio-phys / BioEn

BioEn - Bayesian Inference Of ENsembles

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Creating `Observables` in a python session might crash the interpreter.

kain88-de opened this issue · comments

print('ERROR: The experimental data type {} is not implemented in BioEn yet. ' \
'Please try \"generic\" (useful for distances, NOEs, CS, J-couplings, ' \
'PREs etc.)'.format(experiment))
sys.exit()

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.

sys.exit(0)

sys.exit(0)

sys.exit(0)

sys.exit(0)

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