Skip to content

Add details about validation target when reporting validation errors in read mode (warnings)#844

Merged
ehennestad merged 10 commits into
mainfrom
add-validation-reporting-target
Jul 2, 2026
Merged

Add details about validation target when reporting validation errors in read mode (warnings)#844
ehennestad merged 10 commits into
mainfrom
add-validation-reporting-target

Conversation

@ehennestad

@ehennestad ehennestad commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Background

io.createParsedType is responsible for creating neurodata objects when reading NWB files. It currently catches all exceptions on read to enrich the error message with what neurodata type and what file location the validation fails for, in order to support troubleshooting.

As part of ongoing work (PR #830) to support lenient read (warn instead of error when data validation fails), we introduced the helper function reportSchemaViolation in PR #836.

Problem

This new function will produce warnings instead of errors for validation failures, but MATLAB does not have any mechanism for catching warnings. If the warning does not carry information about the specific neurodata type and file location, trouble shooting becomes much harder.

Solution

This PR adds a validationTarget context which is set in io.createParsedType and carries information about the type and path of the current object being constructed. This context is read in the reportSchemaViolation function in order to enrich the warning message with what neurodata type and what file location the warning applies to.

Example

Reading a file from Dandiset 000011

nwbRead('sub-255200_ses-20140910_behavior+ecephys+ogen.nwb')

Before:

Warning: Invalid shape for property "data". Value of size [15 1] is invalid.  Must be one of:
    - Rank 1 with dimensions of size: [1] The non-conforming value is kept. If you maintain this data, consider correcting it before export. 
> In matnwb.common.validation.reportSchemaViolation (line 36)
In types.util.validateShape (line 48)
In types.core/DynamicTableRegion/validate_data (line 58)
In types.core/NWBData/set.data (line 48)
In types.core/NWBData (line 37)
In types.core/VectorData (line 30)
In types.core/DynamicTableRegion (line 32)
In io.createParsedType (line 32)
In io.parseDataset (line 65)
In io.parseGroup (line 26)
In io.parseGroup (line 37)
In nwbRead (line 106) 

After:

Warning: Validation failed while reading object of type "types.core.DynamicTableRegion" at file location "/units/electrodes":
Invalid shape for property "data". Value of size [15 1] is invalid.  Must be one of:
    - Rank 1 with dimensions of size: [1]
Note: The non-conforming value is kept. If you maintain this data, consider correcting it before export. 
> In matnwb.common.validation.reportSchemaViolation (line 47)
In types.util.validateShape (line 48)
In types.core/DynamicTableRegion/validate_data (line 58)
In types.core/NWBData/set.data (line 48)
In types.core/NWBData (line 37)
In types.core/VectorData (line 30)
In types.core/DynamicTableRegion (line 32)
In io.createParsedType (line 23)
In io.parseDataset (line 65)
In io.parseGroup (line 26)
In io.parseGroup (line 37)
In nwbRead (line 106) 

How to test the behavior?

Show here how to reproduce the new behavior (can be a bug fix or a new feature)

Checklist

  • Have you ensured the PR description clearly describes the problem and solutions?
  • Have you checked to ensure that there aren't other open or previously closed Pull Requests for the same change?
  • If this PR fixes an issue, is the first line of the PR description fix #XX where XX is the issue number?

@ehennestad ehennestad changed the title Add validation reporting target Add details about validation target when reporting validation errors in read mode (warnings) Jul 1, 2026
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.30%. Comparing base (d436ce3) to head (0b05499).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #844      +/-   ##
==========================================
+ Coverage   95.29%   95.30%   +0.01%     
==========================================
  Files         218      219       +1     
  Lines        7671     7696      +25     
==========================================
+ Hits         7310     7335      +25     
  Misses        361      361              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ehennestad ehennestad added this pull request to the merge queue Jul 2, 2026
Merged via the queue into main with commit 931826e Jul 2, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants