Skip to content

Commit f0e594e

Browse files
Merge pull request #204 from NeurodataWithoutBorders/fix_try_except_pynwb_validation
[Bug] encapsulate nwbfile after io.read() in same try/except
2 parents 21f9005 + 606457c commit f0e594e

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

nwbinspector/nwbinspector.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -455,29 +455,29 @@ def inspect_nwb(
455455
filterwarnings(action="ignore", message="No cached namespaces found in .*")
456456
filterwarnings(action="ignore", message="Ignoring cached namespace .*")
457457
with pynwb.NWBHDF5IO(path=nwbfile_path, mode="r", load_namespaces=True, driver=driver) as io:
458-
if skip_validate:
458+
if not skip_validate:
459459
validation_errors = pynwb.validate(io=io)
460-
if any(validation_errors):
461-
for validation_error in validation_errors:
462-
yield InspectorMessage(
463-
message=validation_error.reason,
464-
importance=Importance.PYNWB_VALIDATION,
465-
check_function_name=validation_error.name,
466-
location=validation_error.location,
467-
file_path=nwbfile_path,
468-
)
460+
for validation_error in validation_errors:
461+
yield InspectorMessage(
462+
message=validation_error.reason,
463+
importance=Importance.PYNWB_VALIDATION,
464+
check_function_name=validation_error.name,
465+
location=validation_error.location,
466+
file_path=nwbfile_path,
467+
)
468+
469469
try:
470470
nwbfile = io.read()
471+
for inspector_message in run_checks(nwbfile=nwbfile, checks=checks):
472+
inspector_message.file_path = nwbfile_path
473+
yield inspector_message
471474
except Exception as ex:
472475
yield InspectorMessage(
473476
message=traceback.format_exc(),
474477
importance=Importance.ERROR,
475-
check_function_name=f"{type(ex)}: {str(ex)}",
478+
check_function_name=f"During io.read() - {type(ex)}: {str(ex)}",
476479
file_path=nwbfile_path,
477480
)
478-
for inspector_message in run_checks(nwbfile, checks=checks):
479-
inspector_message.file_path = nwbfile_path
480-
yield inspector_message
481481

482482

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

0 commit comments

Comments
 (0)