NeurodataWithoutBorders / pynwb

A Python API for working with Neurodata stored in the NWB Format
https://pynwb.readthedocs.io
Other
178 stars 84 forks source link

validator error messages #835

Open bendichter opened 5 years ago

bendichter commented 5 years ago

Feature Request

The error messages in the pynwb validator could be more helpful. For instance, I am trying to validate a file right now and I am getting the error:

Traceback (most recent call last):
  File "/Users/bendichter/anaconda3/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/Users/bendichter/anaconda3/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/bendichter/dev/pynwb/src/pynwb/validate.py", line 69, in <module>
    main()
  File "/Users/bendichter/dev/pynwb/src/pynwb/validate.py", line 63, in main
    ret = ret or _validate_helper(io=io)
  File "/Users/bendichter/dev/pynwb/src/pynwb/validate.py", line 21, in _validate_helper
    errors = validate(**kwargs)
  File "/Users/bendichter/dev/pynwb/src/pynwb/form/utils.py", line 396, in func_call
    return func(**parsed['args'])
  File "/Users/bendichter/dev/pynwb/src/pynwb/__init__.py", line 185, in validate
    return validator.validate(builder)
  File "/Users/bendichter/dev/pynwb/src/pynwb/form/utils.py", line 381, in func_call
    return func(self, **parsed['args'])
  File "/Users/bendichter/dev/pynwb/src/pynwb/form/validate/validator.py", line 232, in validate
    return validator.validate(builder)
  File "/Users/bendichter/dev/pynwb/src/pynwb/form/utils.py", line 381, in func_call
    return func(self, **parsed['args'])
  File "/Users/bendichter/dev/pynwb/src/pynwb/form/validate/validator.py", line 466, in validate
    ret.extend(validator.validate(sub_builder))
  File "/Users/bendichter/dev/pynwb/src/pynwb/form/utils.py", line 381, in func_call
    return func(self, **parsed['args'])
  File "/Users/bendichter/dev/pynwb/src/pynwb/form/validate/validator.py", line 372, in validate
    if not check_shape(self.spec.shape, shape):
  File "/Users/bendichter/dev/pynwb/src/pynwb/form/validate/validator.py", line 131, in check_shape
    if len(expected) == len(received):
TypeError: object of type 'NoneType' has no len()

It would be nice if I knew which object is causing this error.

Checklist

bendichter commented 5 years ago

I am not generating this file myself, so I can't easily pare it down and isolate the issue. If you would like to work on this, let me know and I'll send the file.

oruebel commented 5 years ago

Looking at the code, I think the received object when calling def check_shape(expected, received): must be None here (otherwise if expected would be None the function should have returned True already). This means in pynwb/form/validate/validator.py", line 372, in if not check_shape(self.spec.shape, shape): the variable shape which is computed by get_shape(data) in line 371 seems to evaluate to None for some reason.

I think to get a more informative error message all you should need to do is to change line 372 in pynwb/src/pynwb/form/validate/validator.py from if not check_shape(self.spec.shape, shape): to if shape is None or (not check_shape(self.spec.shape, shape)):. Note, I believe this change would probably need to be done in HDMF rather than in PyNWB (since pynwb.form is being moved to HDMF) @ajtritt .