Add context-aware schema violation reporting#836
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a centralized, context-aware mechanism for reporting schema validation violations so MatNWB can be lenient when reading existing files (warn + keep value) while remaining strict during editing (error by default, optionally warn for backwards-compatible validators) and writing (always error to prevent invalid NWB output).
Changes:
- Added
matnwb.common.validation.reportSchemaViolationplus a new internal validation context (READ/EDIT/WRITE) to gate warning vs. error behavior. - Set the validation context during deserialization (
io.createParsedType=>READ) and export (NwbFile.export=>WRITE). - Routed DynamicTable schema-violation reporting through the new shared reporter and added unit tests for the new behavior.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
NwbFile.m |
Sets schema validation context to WRITE during export and restores it afterward. |
+io/createParsedType.m |
Sets schema validation context to READ during parsed type construction and restores it afterward. |
+types/+util/+dynamictable/validateUniqueColnames.m |
Uses the shared reporter for duplicate colname violations. |
+types/+util/+dynamictable/syncNamedColumn.m |
Skips syncing on read using the new read-context helper. |
+types/+util/+dynamictable/checkConfig.m |
Uses the shared reporter for colnames mismatch and references new read-context helper. |
+types/+util/validationContext.m |
Removes the old strict/read context helper. |
+tests/+unit/+io/testCreateParsedType.m |
Updates tests to use the new validation context setter. |
+tests/+unit/+common/+validation/ReportSchemaViolationTest.m |
Adds focused tests for context-aware schema violation reporting behavior. |
+matnwb/+common/+validation/reportSchemaViolation.m |
Implements the shared error/warn reporting helper with optional causes and WarnInsteadOfError. |
+matnwb/+common/+validation/isReadContext.m |
Adds a helper for checking read context. |
+matnwb/+common/+validation/+internal/ValidationContext.m |
Adds the READ/EDIT/WRITE enum. |
+matnwb/+common/+validation/+internal/context.m |
Adds process-local get/set for the validation context. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #836 +/- ##
==========================================
- Coverage 95.31% 95.13% -0.19%
==========================================
Files 219 223 +4
Lines 7647 7913 +266
==========================================
+ Hits 7289 7528 +239
- Misses 358 385 +27 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
80d8e8f to
b898712
Compare
Motivation
MatNWB needs to report schema validation violations differently depending on when validation runs (PR #830, PR #832). Values read from existing files should remain readable, so read-time schema violations should warn. Values being written should not produce invalid NWB output, so write-time schema violations should always error. During normal in-memory editing, validation should error by default, while specific backwards-compatible validators can opt into warning instead of error (This requirement was added during review in PR #837).
This PR adds
matnwb.common.validation.reportSchemaViolationas the shared reporting helper for schema validation failures. It gateswarninganderrorthrough a validation context withREAD,EDIT, andWRITEmodes:READalways warns.EDITerrors by default.EDITcan warn when a validator passesWarnInsteadOfError=true.WRITEalways errors.The read context is set while deserializing parsed types, and the write context is set during
NwbFile.export. Existing DynamicTable validation paths now use the shared reporter.How to test the behavior?
Checklist
fix #XXwhereXXis the issue number?🤖 Generated with Codex