mnmelo / mdreader

MDreader: A package to boost MD data analysis with parallelization
GNU General Public License v2.0
7 stars 5 forks source link

Nicer error message when a file is missing #3

Closed jbarnoud closed 8 years ago

jbarnoud commented 8 years ago

If a program that relies on MDreader is called without -f, -s, or -n, then the program fails during do_parse whith a python traceback.

The message for a missing -f looks like:

Traceback (most recent call last):
  File "./count_between.py", line 22, in <module>
    md = user_cli()
  File "./count_between.py", line 18, in user_cli
    md.do_parse()
  File "/home/jon/Envs/dev2/local/lib/python2.7/site-packages/MDreader/mdreader.py", line 483, in do_parse
    map(check_file,(self.opts.topol,)+tuple(self.opts.infile))
  File "/home/jon/Envs/dev2/local/lib/python2.7/site-packages/MDreader/mdreader.py", line 63, in check_file
    raise IOError('Can\'t find file %s' % (fname))
IOError: Can't find file t

The message for a missing -s looks like:

Traceback (most recent call last):
  File "./count_between.py", line 22, in <module>
    md = user_cli()
  File "./count_between.py", line 18, in user_cli
    md.do_parse()
  File "/home/jon/Envs/dev2/local/lib/python2.7/site-packages/MDreader/mdreader.py", line 483, in do_parse
    map(check_file,(self.opts.topol,)+tuple(self.opts.infile))
  File "/home/jon/Envs/dev2/local/lib/python2.7/site-packages/MDreader/mdreader.py", line 63, in check_file
    raise IOError('Can\'t find file %s' % (fname))
IOError: Can't find file topol.tpr

And the message for a missing -n looks like:

Traceback (most recent call last):
  File "./count_between.py", line 22, in <module>
    md = user_cli()
  File "./count_between.py", line 18, in user_cli
    md.do_parse()
  File "/home/jon/Envs/dev2/local/lib/python2.7/site-packages/MDreader/mdreader.py", line 500, in do_parse
    self._parse_ndx()
  File "/home/jon/Envs/dev2/local/lib/python2.7/site-packages/MDreader/mdreader.py", line 512, in _parse_ndx
    self._get__ndx_atgroups()
  File "/home/jon/Envs/dev2/local/lib/python2.7/site-packages/MDreader/mdreader.py", line 923, in _get__ndx_atgroups
    resnames = numpy.unique(self.atoms.resnames())
TypeError: 'numpy.ndarray' object is not callable

MDreader could display a more human friendly error message.

mnmelo commented 8 years ago

Silly bug because I didn't clean up properly when migrating to MDAnalysis v0.11.

jbarnoud commented 8 years ago

While the issue with a missing -n is fixed, missing file for -f and -s still give ugly tracebacks.

mnmelo commented 8 years ago

Good point

mnmelo commented 8 years ago

Hmm, just came back to this. What is wrong with the current error messages? That a traceback is displayed? What alternative would you suggest?

I'm not sure this can be fixed on the MDreader side. It is a library meant to be used by other scripts; it shouldn't suppress traceback or force the interpreter to quit on its own. It's up to those scripts to handle exceptions.

OTOH, we can have an MDreader creation flag raise_exc=False. Depending on the value for this flag we would call sys.exit("error msg") or raise SomeException("error msg").

jbarnoud commented 8 years ago

Since MDReader extend argparse, one could expect it to validate the inputs and to catch the missing ones. You would expect a program that use argparse to fail gracefully when an input is missing.

Indeed, it may be useful sometime to be able to catch the exception. Then it would be nice to be also able to distinguish between the exception for a missing traj and the one for a missing topology. The flag, seems a good solution.