Skip to content

Commit

Permalink
Merge pull request #204 from NeurodataWithoutBorders/fix_try_except_p…
Browse files Browse the repository at this point in the history
…ynwb_validation

[Bug] encapsulate nwbfile after io.read() in same try/except
  • Loading branch information
CodyCBakerPhD authored May 4, 2022
2 parents 21f9005 + 606457c commit f0e594e
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions nwbinspector/nwbinspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,29 +455,29 @@ def inspect_nwb(
filterwarnings(action="ignore", message="No cached namespaces found in .*")
filterwarnings(action="ignore", message="Ignoring cached namespace .*")
with pynwb.NWBHDF5IO(path=nwbfile_path, mode="r", load_namespaces=True, driver=driver) as io:
if skip_validate:
if not skip_validate:
validation_errors = pynwb.validate(io=io)
if any(validation_errors):
for validation_error in validation_errors:
yield InspectorMessage(
message=validation_error.reason,
importance=Importance.PYNWB_VALIDATION,
check_function_name=validation_error.name,
location=validation_error.location,
file_path=nwbfile_path,
)
for validation_error in validation_errors:
yield InspectorMessage(
message=validation_error.reason,
importance=Importance.PYNWB_VALIDATION,
check_function_name=validation_error.name,
location=validation_error.location,
file_path=nwbfile_path,
)

try:
nwbfile = io.read()
for inspector_message in run_checks(nwbfile=nwbfile, checks=checks):
inspector_message.file_path = nwbfile_path
yield inspector_message
except Exception as ex:
yield InspectorMessage(
message=traceback.format_exc(),
importance=Importance.ERROR,
check_function_name=f"{type(ex)}: {str(ex)}",
check_function_name=f"During io.read() - {type(ex)}: {str(ex)}",
file_path=nwbfile_path,
)
for inspector_message in run_checks(nwbfile, checks=checks):
inspector_message.file_path = nwbfile_path
yield inspector_message


def run_checks(nwbfile: pynwb.NWBFile, checks: list):
Expand Down

0 comments on commit f0e594e

Please sign in to comment.